Select specific columns in NumPy array using colon notation

后端 未结 1 699
醉话见心
醉话见心 2020-12-11 21:16

I have a 40000 by 60 Numpy array, and I want to sth like this:

mat[:,[0:13,19:23,23:31,39:59]]

Obviously, it does not work. Is there a smar

相关标签:
1条回答
  • 2020-12-11 21:35

    Use np.r_ -

    mat[:,np.r_[0:13,19:23,23:31,39:59]]
    

    Sample run -

    In [48]: mat = np.random.rand(100,1000)
    
    In [50]: mat[:,np.r_[0:13,19:23,23:31,39:59]].shape
    Out[50]: (100, 45)
    
    In [51]: 13+4+8+20
    Out[51]: 45
    
    0 讨论(0)
提交回复
热议问题