remove a specific column in numpy

后端 未结 3 811
忘掉有多难
忘掉有多难 2020-12-15 18:16
>>> arr = np.array([[1,2,3,4], [5,6,7,8], [9,10,11,12]])
>>> arr
array([[ 1,  2,  3,  4],
       [ 5,  6,  7,  8],
       [ 9, 10, 11, 12]])
         


        
3条回答
  •  一个人的身影
    2020-12-15 18:48

    If you ever want to delete more than one columns, you just pass indices of columns you want deleted as a list, like this:

    >>> a = np.arange(12).reshape(3,4)
    >>> a
    array([[ 0,  1,  2,  3],
           [ 4,  5,  6,  7],
           [ 8,  9, 10, 11]])
    >>> np.delete(a, [1,3], axis=1)
    array([[ 0,  2],
           [ 4,  6],
           [ 8, 10]])
    

提交回复
热议问题