[Numpy-discussion] Is this an indexing bug?

Stefan van der Walt stefan@sun.ac...
Tue Jun 19 06:28:52 CDT 2007


On Tue, Jun 19, 2007 at 12:35:05PM +0200, Sturla Molden wrote:
> On 6/19/2007 12:14 PM, Sturla Molden wrote:
> 
> > h[0,:,numpy.arange(14)] is a case of "sdvanced indexing". You can also 
> > see that
> > 
> >  >>> h[0,:,[0,1,2,3,4,5,6,7,8,9,10,11,12,13]].shape
> > (14, 4)
> 
> Another way to explain this is that numpy.arange(14) and 
> [0,1,2,3,4,5,6,7,8,9,10,11,12,13] is a sequence (i.e. iterator).  So 
> when NumPy iterates the sequence, the iterator yields a single integer, 
> lets call it I. Using this integer as an index to h, gives a = h[0,:,I] 
> which has shape=(4,). This gives us a sequence of arrays of length 4. In 

If you follow this analogy,

x = N.arange(100).reshape((10,10))
x[:,N.arange(5)].shape

should be (5, 10), while in reality it is (10, 5).

Cheers
Stéfan


More information about the Numpy-discussion mailing list