[Numpy-discussion] indexing question

Tom K. tpk@kraussfamily....
Tue Mar 30 09:13:12 CDT 2010


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)

Whoa!  Trimming my array to a desired number ends up moving the last
dimension to the first!

In [4]: np.__version__
Out[4]: '1.3.0'

...
In [7]: x[:,:,:,:,:,[1,2,3]].shape
Out[7]: (10, 1, 1, 1, 14, 3)

This looks right...

In [8]: x[...,[1,2,3]].shape
Out[8]: (10, 1, 1, 1, 14, 3)

and this...

In [9]: x[...,[1,2,3]][:,0,0,0].shape
Out[9]: (10, 14, 3)

...
In [11]: x[:,0,0,0][...,[1,2,3]].shape
Out[11]: (10, 14, 3)

Either of the last 2 attempts above results in what I want, so I can do
that... I just need some help deciphering when and why the first thing
happens.

-- 
View this message in context: http://old.nabble.com/indexing-question-tp28083162p28083162.html
Sent from the Numpy-discussion mailing list archive at Nabble.com.



More information about the NumPy-Discussion mailing list