5
votes

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 smarter way to do this than concatenation?

1

1 Answers

5
votes

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