[Numpy-discussion] DEP: Deprecate boolean array indices with non-matching shape #4353

Nathaniel Smith njs at pobox.com
Thu Jun 4 22:41:36 EDT 2015

On Thu, Jun 4, 2015 at 6:22 PM, Benjamin Root <ben.root at ou.edu> wrote:
> On Thu, Jun 4, 2015 at 9:04 PM, Nathaniel Smith <njs at pobox.com> wrote:
>> On Thu, Jun 4, 2015 at 5:57 PM, Nathaniel Smith <njs at pobox.com> wrote:
>> One place where the current behavior is particularly baffling and annoying is when you have multiple boolean masks in the same indexing operation. I think everyone would expect this to index separately on each axis ("outer product indexing" style, like slices do), and that's really the only useful interpretation, but that's not what it does...:
> As a huge user of boolean indexes, I have never expected this to work in any way, shape or form. I don't think it works in matlab (but someone should probably check that), so you wouldn't have to worry about converts missing a feature from there. I have always been told that boolean indexing will produce a flattened array, and I wouldn't want to be dealing with magic when the array does not match up right.

Note that there are two types of boolean indexing:

type 1: arr[mask] where mask is n-d (ideally the same shape as "arr",
but I think that it *is* broadcast if not). This always produces 1-d

type 2: arr[..., mask, ...], where mask is 1-d and only applies to the
given dimension.

My comment was about the second type. Are your comments about the
second type? The second type definitely does not produce a flattened

In [7]: a = np.arange(9).reshape(3, 3)

In [8]: a[np.asarray([True, False, True]), :]
array([[0, 1, 2],
       [6, 7, 8]])


Nathaniel J. Smith -- http://vorpus.org

More information about the NumPy-Discussion mailing list