[Numpy-discussion] boolean indexing change
Ralf Gommers
ralf.gommers@googlemail....
Sun Jun 10 10:13:28 CDT 2012
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20120610/65d7091e/attachment-0001.html
More information about the NumPy-Discussion
mailing list