且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何删除numpy.array中的列

更新时间:2022-06-13 07:54:10

鉴于其名称,我认为标准方法应为delete:

Given its name, I think the standard way should be delete:

import numpy as np

A = np.delete(A, 1, 0)  # delete second row of A
B = np.delete(B, 2, 0)  # delete third row of B
C = np.delete(C, 1, 1)  # delete second column of C

根据 numpy的文档页面numpy.delete的参数如下:

numpy.delete(arr, obj, axis=None)

  • arr引用输入数组
  • obj指的是哪些子数组(例如列/行号或数组的切片)和
  • axis是指按列(axis = 1)或按行(axis = 0)删除操作.
  • arr refers to the input array,
  • obj refers to which sub-arrays (e.g. column/row no. or slice of the array) and
  • axis refers to either column wise (axis = 1) or row-wise (axis = 0) delete operation.