将 3D 数组转换为 2D
Convert a 3D array to 2D
我得到了一个形状为 (1,3,300) 的 numpy 数组,我想去掉第一个轴,只得到 3*300 二维数组。我该怎么做?
我看到了几个这样的问题
要求更复杂的地方。我的看起来很简单。有什么简单的方法吗?
np.squeeze
?
In [1]: import numpy as np
In [2]: a = np.arange(3*300).reshape(3,300)
In [3]: a.shape
Out[3]: (3, 300)
In [4]: a = a[np.newaxis, ...]
In [5]: a.shape
Out[5]: (1, 3, 300)
In [6]: b = np.squeeze(a, axis=0)
In [7]: b.shape
Out[7]: (3, 300)
我得到了一个形状为 (1,3,300) 的 numpy 数组,我想去掉第一个轴,只得到 3*300 二维数组。我该怎么做?
我看到了几个这样的问题
np.squeeze
?
In [1]: import numpy as np
In [2]: a = np.arange(3*300).reshape(3,300)
In [3]: a.shape
Out[3]: (3, 300)
In [4]: a = a[np.newaxis, ...]
In [5]: a.shape
Out[5]: (1, 3, 300)
In [6]: b = np.squeeze(a, axis=0)
In [7]: b.shape
Out[7]: (3, 300)