[Numpy-discussion] odd behavior for numpy.ndarray index?

Orest Kozyar orest.kozyar@gmail....
Sun Sep 9 21:36:11 CDT 2007


In the following output (see below), why would x[1,None] work, but
x[1,None,2] or even x[1,2,None] not work?  

Incidentally, I would be very interested in a solution that allows me to
index numpy arrays using a list/iterable that might contain None values.  Is
there a straightforward way to do so, or should I just use list
comprehensions (i.e. [x[a] for a in indices if a])?

Thanks!
Orest


In [122]: x = arange(5)

In [123]: x[1]
Out[123]: 1

In [124]: x[None]
Out[124]: array([[0, 1, 2, 3, 4]])

In [125]: x[1,None]
Out[125]: array([1])

In [126]: x[1,None,2]
---------------------------------------------------------------------------
<type 'exceptions.IndexError'>            Traceback (most recent call last)

c:\documents\research\programs\python\epl\src\<ipython console> in
<module>()

<type 'exceptions.IndexError'>: invalid inde



More information about the Numpy-discussion mailing list