标签: python arrays numpy
我想将numpy数组(n,1)转换为(n,)。是否可以在不必遍历数组的情况下执行此操作?
答案 0 :(得分:0)
使用numpy.squeeze:
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搜索找到这个答案。 。