我尝试通过
删除numpy ndarray的第一列(例如A,B,C ... A,B)x = np.delete(x, 0, axis=1)
或
x = np.delete(x, 0, axis=0)
然而,这不起作用。
ndarray shape = ( 30000, 120, 15)
[[['A' 0.0 0.0 ..., 0.0 0.0 'Y']
['B' 0.0 0.0 ..., 0.0 0.0 'Y']
['C' 0.0 0.0 ..., 0.0 0.0 'N']
...,
['A' 0.0 0.0 ..., 0.0 0.0 'Y']
['B' 41.0 0.0 ..., 0.0 0.0 'N']]]
我如何解决这个问题......谢谢。
答案 0 :(得分:3)
该列是数组的第三维,您需要axis = 2
:
import numpy as np
x = np.array([[['A', 1, 2],
['B', 2, 3]],
[['A', 1, 2],
['B', 2, 3]]])
x.shape
#(2, 2, 3)
np.delete(x, 0, axis=2)
#array([[['1', '2'],
# ['2', '3']],
#
# [['1', '2'],
# ['2', '3']]],
# dtype='<U1')
或者您可以使用切片索引:
x[...,1:]
#array([[['1', '2'],
# ['2', '3']],
#
# [['1', '2'],
# ['2', '3']]],
# dtype='<U1')