[NumPy-Tickets] [NumPy] #2069: boolean indexing with no matches should leave shape same
NumPy Trac
numpy-tickets@scipy....
Mon Mar 12 13:04:34 CDT 2012
#2069: boolean indexing with no matches should leave shape same
--------------------+-------------------------------------------------------
Reporter: shaunc | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone: Unscheduled
Component: Other | Version: 1.6.1
Keywords: |
--------------------+-------------------------------------------------------
Old description:
> >>> a = array( [ [ 1, 1 ] ] )
> >>> a[ a == 0 ].shape
> (0, )
>
> This is also puzzling as:
> >>> aa == 0
> array([[False, False]], dtype=bool)
>
> >>> b = [ [ False, False ] ]
> >>> a [ b ]
> >>> aa[ bb ]
> array([[1, 1],
> [1, 1]])
New description:
{{{
>>> a = array( [ [ 1, 1 ] ] )
>>> a[ a == 0 ].shape
(0, )
}}}
This is also puzzling as:
{{{
>>> aa == 0
array([[False, False]], dtype=bool)
>>> b = [ [ False, False ] ]
>>> a [ b ]
>>> aa[ bb ]
array([[1, 1],
[1, 1]])
}}}
--
Comment(by mwiebe):
The first thing you're seeing is by design. NumPy picks out the the array
elements which are flagged with True, and returns them compressed into a
one-dimensional array.
The second thing you're seeing is a bug. The fancy indexing code is
treating the [[False, False]] as an integer array, so is using the False
values as an integer index instead of as a boolean. If you force it to be
a boolean array, it works as expected:
{{{
In [10]: a[b]
Out[10]:
array([[1, 1],
[1, 1]])
In [11]: a[np.array(b)]
Out[11]: array([], dtype=int32)
}}}
--
Ticket URL: <http://projects.scipy.org/numpy/ticket/2069#comment:1>
NumPy <http://projects.scipy.org/numpy>
My example project
More information about the NumPy-Tickets
mailing list