[Numpy-discussion] bug with assignment into an indexed array?

Benjamin Root ben.root@ou....
Wed Aug 10 15:55:37 CDT 2011

Came across this today when trying to determine what was wrong with my code:

import numpy as np
matched_to = np.array([-1] * 5)
in_ellipse = np.array([False, True, True, True, False])
match = np.array([False, True, True])
matched_to[in_ellipse][match] = 3

I would expect matched_to to now be "array([-1, -1, 3, 3, -1])", but
instead, it is still all -1.

It would seem that unless the view was created by a slice, then the
assignment into the indexed view would not work as expected.  This works:

>>> matched_to[:3][match] = 3

but not:

>>> matched_to[np.array([0, 1, 2])][match] = 3

Note that the following does work:

>>> matched_to[np.array([0, 1, 2])] = 3

Is this a bug, or was I wrong to expect this to work this way?

Ben Root
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20110810/9cec285d/attachment.html 

More information about the NumPy-Discussion mailing list