假设我有以下3x4阵列
master_array = [[1, 3, 4, 5],
[6, 5, 4, 1],
[7, 8, 4, 1]]
然后,我想删除3个1x4子阵列中的每一个的4号。我会使用以下内容吗?
for i in range(master_array.shape[0]):
np.delete(master_array[i], 3)
然后,当我打印master_array时,我会得到吗?
[[1, 3, 5],
[6, 5, 1],
[7, 8, 1]]
答案 0 :(得分:0)
如果master_array
是列表列表,例如您的示例,则可以
master_array = [[1, 3, 4, 5],
[6, 5, 4, 1],
[7, 8, 4, 1]]
for row in master_array:
del row[2]
如果master_array
确实是一个numpy数组,你只需要
master_array = np.array([[1, 3, 4, 5],
[6, 5, 4, 1],
[7, 8, 4, 1]])
np.delete(master_array, 2, axis=1)