我有一个维度为 (48, 366, 3) 的 numpy 数组,我想要移除数组的最后一列,使其变为 (48, 365, 3)。最好的方法是什么?(所有条目都是整数。我正在使用 Python v2.6)
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,:]
沿着这条线:
In []: A= rand(48, 366, 3)
In []: A.shape
Out[]: (48, 366, 3)
In []: A= A[:, :-1, :]
In []: A.shape
Out[]: (48, 365, 3)