Reputation: 1480
Is it possible to index a numpy array such that the first index is the start index and the second index is the number of samples/indices to grab relative to the start index?
a = np.arange(10)
b = a[3:7] # b=[3,4,5,6]
c = a[3:+4] # desired, take 4 samples from index 3
Upvotes: 0
Views: 972
Reputation: 22776
You can do either a[i : i + x]
or a[i:][:x]
, where the indexing starts at i
and grabs x
elements.
Upvotes: 2