Why using an array as an index changes the shape of a multidimensional ndarray?

As @hpaulj mentioned in the comments, this behaviour is because of mixing basic slicing and advanced indexing: a = np.arange(120).reshape(4,5,3,2) b = a[:,[1,2,3,4,0],:,0] In the above code snippet, what happens is the following: when we do basic slicing along last dimension, it triggers a __getitem__ call. So, that dimension is gone. (i.e. no singleton dimension) … Read more