0
点赞
收藏
分享

微信扫一扫

numpy.array 二维矩阵删除特定的某些行或者列


import numpy as np
a = np.array([[0,2, 0],
[0,5, 0],
[0,8, 0]])
del_index = []
for col in range(3):
if a[0][col] == 0:
del_index.append(col)
print(del_index)
a = np.delete(a, del_index, axis = 1) # axis=1 删除列,axis=0 删除行
print(a)

输出:

[0, 2]  # 要删除的列

# 删除后的结果
[[2]
[5]
[8]]


举报

相关推荐

0 条评论