I have a 3d array in numpy
that I would like to index on two of these axes. For one of the axes I am using a simple integer index, whereas on the other axis I use a list indexing. If I apply the indexes separately, the result is different from when I apply them within one pair of brackets:
import numpy as np
a = np.ones((10, 20, 30))
print(a.shape)
> (10, 20, 30)
# the unexpected result:
print(a[3,:,[1,2]].shape)
> (2, 20)
# the two expected results:
print(a[3][:,[1,2]].shape)
> (20, 2)
print(a[:,:,[1,2]][3].shape)
> (20, 2)
Could you please explain to me why this is the expected/desired behaviour? For me, this looks inconsistent.