将numpy数组形状(n,1)转换为shape(n,)

时间:2015-04-19 20:19:05

标签: python arrays numpy

我想将numpy数组(n,1)转换为(n,)。是否可以在不必遍历数组的情况下执行此操作?

1 个答案:

答案 0 :(得分:0)

使用numpy.squeeze

>>> x = np.array([[[0], [1], [2]]])
>>> x.shape
(1, 3, 1)
>>> np.squeeze(x).shape
(3,)
>>> np.squeeze(x, axis=(2,)).shape
(1, 3)

我很确定你可以通过Google搜索找到这个答案。 。

相关问题