I'd like to select multiple, non-adjacent ranges from a 1d numpy array (or vector).
Suppose:
>>> idx = np.random.randint(100, size=10)
array([82, 9, 11, 94, 31, 87, 43, 77, 49, 50])
This works, of course:
>>> idx[0:3]
array([82, 9, 11])
And this works to fetch via individual indices:
>>> idx[[0,3,4]]
array([82, 94, 31])
But what if I want to select the ranges 0:3
, and 7:
?
I've tried:
>>> idx[[0:3,7:]]
SyntaxError: invalid syntax
Is there a simple way to do this, or do I need to generate them separately and concatenate?
See Question&Answers more detail:os