我得到了一个形状为 (1,3,300) 的 numpy 数组,我想去掉第一个轴并只得到 3*300 2D 数组。我该怎么做?
我看到了几个这样的问题 numpy with python: convert 3d array to 2d 要求更复杂的地方。我的看起来很简单。有什么简单的方法吗?
最佳答案
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)
关于arrays - 将 3D 数组转换为 2D,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49963126/