I'm trying to understand some code and I've encountered a negative index in a 3d array and I'm confused.
First a toy example:
import numpy as np
mis = np.random.rand(2, 3, 4)
np.sort(mis, axis=2)[:, :, -2]
Out[428]:
array([[0.409, 0.406, 0.668],
[0.806, 0.715, 0.442]])
Ok. so playing around with this toy example I changed -2 to +2:
np.sort(mis, axis=2)[:, :, 2]
Out[429]:
array([[0.409, 0.406, 0.668],
[0.806, 0.715, 0.442]])
Whats going on here, why is the answer the same ? In my real data the size of mis in all 3 dimensions could be much larger so I want to understand this properly. Thanks!
Edit: Note I've tried the toy with mis having dimension (2,3,20) and the results are not the same from that - but this just confuses me more!