I have just stumbled over a numpy index behavior which I do not quite understand. It seems like numpy is changing the order of my axes depending on the indexing schema. Unfortunately, I cannot find an explanation for the following in the documentation. Could somebody explain to me what is going on?
# This is expected: dimension 1 is reduced to length 1:
print np.ndarray(shape=(3,3,3,3))[:, [0], :, :].shape
>>> (3, 1, 3, 3)
# This is the unexpected behavior:
print np.ndarray(shape=(3,3,3,3))[:, [0], :, 0].shape
>>> (1, 3, 3)
I would expected the second command to yield (3, 1, 3). Why does does my shape of the first two dimensions change if I pick an element from the forth? Thanks a lot in advance!
Edit: I see this on numpy 1.11.0 with python 2.7.11