[Numpy-discussion] using boolean arrays as indices
oliphant at ee.byu.edu
Mon Mar 27 16:57:02 CST 2006
Michael Sorich wrote:
> 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?
Yes. Currently, you can only use Boolean indexing using
X[obj] which is equivalent to (but faster than) X[obj.nonzero()]
There is no way currently to use Boolean indexing on a single axis. A
useful specification would need to be made that is consistent with the
current definition along with an implementation.
You could use instead
This selects out sub-arrays along a particular axis.
More information about the Numpy-discussion