[SciPy-user] Boolean indexing

Johannes Loehnert a.u.r.e.l.i.a.n at gmx.net
Wed May 3 04:11:37 EDT 2006


Hi,

I just stumbled upon something...

In [15]: a
Out[15]:
array([[0, 1],
       [2, 3],
       [4, 5],
       [6, 7],
       [8, 9]])

In [16]: b = array([False, True, True, True, False])

In [17]: a[b]
Out[17]:
array([[2, 3],
       [4, 5],
       [6, 7]])

In [18]: a[b,:]
---------------------------------------------------------------------------
exceptions.IndexError                                Traceback (most recent 
call last)

/home/jloehnert/python/ratchet/<console>

IndexError: arrays used as indices must be of integer type

In [19]: a[nonzero(b),:]
Out[19]:
array([[2, 3],
       [4, 5],
       [6, 7]])

In [20]: numpy.__version__
Out[20]: '0.9.7.2473'


Why does a[b, :] not work?

Johannes




More information about the SciPy-User mailing list