[Numpy-discussion] indexing question

Robert Kern robert.kern@gmail....
Tue Mar 30 09:52:24 CDT 2010


On Tue, Mar 30, 2010 at 09:46, Charles R Harris
<charlesr.harris@gmail.com> wrote:
>
>
> On Tue, Mar 30, 2010 at 8:13 AM, Tom K. <tpk@kraussfamily.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 [1]: import numpy as np
>>
>> In [2]: x=np.zeros((10,1,1,1,14,1024))
>>
>> In [3]: x[:,0,0,0,:,[1,2,3]].shape
>> Out[3]: (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.

-- 
Robert Kern

"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 mailing list