Issue
Given the array:
import numpy as np
arr = np.array(range(10))
print(arr)
[0,1,2,3,4,5,6,7,8,9]
is it possible to get in one single slice ex. arr[1:6:1] the numbers [1, 2, 5]?
I've tried everything, from steps to multiple slicing, it seems I cannot get past the uneven step between the numbers. I'm pretty sure it's not possible, but if it is, I'd like to hear it since I wasted a few hours on this.
Thanks in advance.
Solution
In numpy, you can directly pass a list of indeces instead of a slice object:
arr[[1, 2, 5]]
If there is an underlying pattern to those indeces you can use it to create the index list.
Answered By - user2390182
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.