Reputation: 27
Assuming I have the following numpy 2d array where arr[2,0] = 7
.
arr =
[[1 2 3]
[4 5 6]
[7 8 9]]
How can I achieve a wrapping effect such that when I try to retrieve arr[3,0]
for example, I won't be getting a "index 3 is out of bounds for axis 0 with size 3" but will get arr[0,0] = 1
instead in return?
Thank you!
Upvotes: 1
Views: 196
Reputation: 231595
You can index one dimension at a time with with take
:
In [72]: np.take(arr,3,0, mode='wrap')
Out[72]: array([1, 2, 3])
Upvotes: 1