[Numpy-discussion] boolean masks & lists
Travis E. Oliphant
Tue Nov 6 10:02:13 CST 2007
John Hunter wrote:
> A colleague of mine just asked for help with a pesky bug that turned
> out to be caused by his use of a list of booleans rather than an array
> of booleans as his logical indexing mask. I assume this is a feature
> and not a bug, but it certainly surprised him:
> In : mask = [True, False, False, False, True]
> In : maska = n.array(mask, n.bool)
> In : x = arange(5)
> In : x[mask]
> Out: array([1, 0, 0, 0, 1])
> In : x[maska]
> Out: array([0, 4])
The issues is how to determine what behavior is desired and how to
manage that with all the possibilities.
Right now the rule is that only boolean arrays are treated as masks and
integer arrays mean indexing.
Lists are always interpreted as integer indexing (except in certain
special cases where the list has slice objects in it). Changing this
to something like: lists are interpreted either as boolean or integer
arrays, may be reasonable, but I don't see how we can change it until
1.1 because the rule has already been specified and is consistent if not
obvious in this simple case.
The question is: is anybody using boolean lists specifically according
to the rule in place now?
More information about the Numpy-discussion