[Numpy-discussion] boolean indexing change
Travis Oliphant
travis@continuum...
Sun Jun 10 19:31:36 CDT 2012
It is unfortunate that this was committed to master. This should be backed out and is a blocker for 1.7. Can someone help me identify which commit made the change?
This is a rather significant change and changes the documented behavior of NumPy substantially. This should definitely not occur in 1.7
The documented behavior (Guide to NumPy, pg. 84) of boolean indexing is that
x[obj] is equivalent to x[obj.nonzero()]
The shape of advanced indexing is not restricted to the shape of of x. I suspect this change was made when it was presumed the next release would be 2.0 and such behavior could presumably be changed somewhat? But, was there a discussion about this?
-Travis
On Jun 10, 2012, at 10:13 AM, Ralf Gommers wrote:
> Something that we just ran into trying to merge a scipy PR:
>
> With 1.5.1:
> >>> np.arange(10)[np.array([0,1,0,1,2,3]) > 0]
> array([1, 3, 4, 5])
>
> With current master:
> In [1]: np.arange(10)[np.array([0,1,0,1,2,3]) > 0]
> ---------------------------------------------------------------------------
> ValueError Traceback (most recent call last)
> /Users/rgommers/<ipython-input-1-49ea14823e3d> in <module>()
> ----> 1 np.arange(10)[np.array([0,1,0,1,2,3]) > 0]
>
> ValueError: operands could not be broadcast together with shapes (10) (6)
>
>
> The reason for this is noted in the 2.0.0 release notes:
> "Full-array boolean indexing used to allow boolean arrays with a size
> non-broadcastable to the array size. Now it forces this to be broadcastable.
> Since this affects some legacy code, this change will require discussion
> during alpha or early beta testing, and a decision to either keep the
> stricter behavior, or add in a hack to allow the previous behavior to
> work.
> "
>
> I'm not opposed to the change in principle, but just wanted to note it can lead to code breaking and puzzled users.
>
> Ralf
>
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
More information about the NumPy-Discussion
mailing list