[Numpy-discussion] using boolean arrays as indices

Michael Sorich michael.sorich at gmail.com
Mon Mar 27 16:31:03 EST 2006


If I have a 2D array and I want to use a boolean array to select the rows.
If I use a[boolarray] it works, but if I use a[boolarray, :] an exception is
raised. Is there a reason for this?

eg
>>>N.__version__
'0.9.6'
>>>a = N.arange(10).reshape((2,5))
>>>a
array([[0, 1, 2, 3, 4],
       [5, 6, 7, 8, 9]])
>>>a[N.array([True, False])]
array([[0, 1, 2, 3, 4]])
>>>a[N.array([True, False]),:]
Traceback (most recent call last):
  File "<input>", line 1, in ?
IndexError: arrays used as indices must be of integer type
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20060327/7c2b3c76/attachment.html>


More information about the NumPy-Discussion mailing list