Issue
I have an array like:
a =np.array([[1,2,3,5,8,7,2,1,3,5,1,2,20,21],[3,8,3,9,8,7,10,1,3,5,1,2,20,21]])
requirement:
need to access index value with given step. For an example step value 3. Only index value not an elements value.
Required Output:
[[0,3,6,9,12],[0,3,6,9,12]]
Solution
Use a list comprehension to repeat the range for each row.
a =np.array([[1,2,3,5,8,7,2,1,3,5,1,2,20,21],[3,8,3,9,8,7,10,1,3,5,1,2,20,21]])
indexes = [list(range(0, a.shape[1], 3)) for _ in range(a.shape[0])]
Answered By - Barmar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.