When I want to extract specific "rows" (or a higher-dimensional equivalent) from a numpy array, I know that I can use a tuple of indices:
>>> a = np.zeros((3, 4, 5, 6, 7)) # Create a dummy array
>>> a[:, (1, 2), ...].shape # Get column 1 and 2 and keep the other dimensions as they are
(3, 2, 5, 6, 7)
However, when I use a tuple indexing combined with :
or ...
and integer indices, the dimensions seem to be reordered:
>>> a[:, (1, 2), :, :, 1].shape # Expected output: (3, 2, 5, 6)
(2, 3, 5, 6)
I can work around this by separating the indexing into two parts:
>>> a[:, (1, 2)][..., 1].shape # Gives my desired output
(3, 2, 5, 6)
Why are the dimensions reordered, only when I use both tuple indices and integer indices?