效果:删除第2,3行和第2,3列
[[ 1 2 3 4 5] [ 6 7 8 9 10] [[ 1 4 5] [11 12 13 14 15] => [16 19 20] [16 17 18 19 20] [21 24 25]] [21 22 23 24 25]]
实现
a = np.arange(1,26).reshape((5,5)) a = np.delete(a, [1,2],axis=0) # 删除行 a = np.delete(a, [1,2],axis=1) # 删除列numpy插入一行一列
效果:在原矩阵(3x3)的最后一行和最后一列插入零向量变为4x4
[[1,2,3] [[1,2,3,0] [4,5,6] => [4,5,6,0] [7,8,9]] [7,8,9,0] [0,0,0,0]]
实现:
a = np.arange(1,10).reshape((3,3)) col = np.zeros(3) a = np.c_[a, col] # 3x4 row = np.zeros(4) a = np.r_[a, [row]] # 4x4
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)