[Numpy-discussion] indexing question
Tue Mar 30 09:52:24 CDT 2010
On Tue, Mar 30, 2010 at 09:46, Charles R Harris
> On Tue, Mar 30, 2010 at 8:13 AM, Tom K. <firstname.lastname@example.org> wrote:
>> This one bit me again, and I am trying to understand it better so I can
>> anticipate when it will happen.
>> What I want to do is get rid of singleton dimensions, and index into the
>> last dimension with an array.
>> In : import numpy as np
>> In : x=np.zeros((10,1,1,1,14,1024))
>> In : x[:,0,0,0,:,[1,2,3]].shape
>> Out: (3, 10, 14)
> Hmm... That doesn't look right.
It's a known feature. Slicing and list indexing are separate
subsystems. The list indexing takes priority so the list-indexed axes
end up first in the result. The sliced axes follow them.
"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
-- Umberto Eco
More information about the NumPy-Discussion