Remove one column for a numpy array

前端 未结 2 1719
一整个雨季
一整个雨季 2020-12-09 14:53

I have a numpy array of dimension (48, 366, 3) and I want to remove the last column from the array to make it (48, 365, 3). What is the best way to do that? (All the entries

相关标签:
2条回答
  • 2020-12-09 15:46

    You could try numpy.delete:

    http://docs.scipy.org/doc/numpy/reference/generated/numpy.delete.html

    or just get the slice of the array you want and write it to a new array.

    For example:

    a = np.random.randint(0,2, size=(48,366,3))
    b = np.delete(a, np.s_[-1:], axis=1)
    print b.shape # <--- (48,365,3)
    

    or equivalently:

    b = np.delete(a, -1, axis=1)
    

    or:

    b = a[:,:-1,:]
    
    0 讨论(0)
  • 2020-12-09 15:58

    Along the lines:

    In []: A= rand(48, 366, 3)
    In []: A.shape
    Out[]: (48, 366, 3)
    
    In []: A= A[:, :-1, :]
    In []: A.shape
    Out[]: (48, 365, 3)
    
    0 讨论(0)
提交回复
热议问题