从一个numpy数组中删除一列

33

我有一个维度为 (48, 366, 3) 的 numpy 数组,我想要移除数组的最后一列,使其变为 (48, 365, 3)。最好的方法是什么?(所有条目都是整数。我正在使用 Python v2.6)

2个回答

54
你可以尝试使用 numpy.delete: http://docs.scipy.org/doc/numpy/reference/generated/numpy.delete.html 或者只获取你想要的数组片段并将其写入新数组。
例如:
a = np.random.randint(0,2, size=(48,366,3))
b = np.delete(a, np.s_[-1:], axis=1)
print b.shape # <--- (48,365,3)

或等价于:

b = np.delete(a, -1, axis=1)

或:

b = a[:,:-1,:]

5

沿着这条线:

In []: A= rand(48, 366, 3)
In []: A.shape
Out[]: (48, 366, 3)

In []: A= A[:, :-1, :]
In []: A.shape
Out[]: (48, 365, 3)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接