<br><br><div><span class="gmail_quote">On 1/6/07, <b class="gmail_sendername">Travis Oliphant</b> <<a href="mailto:oliphant@ee.byu.edu">oliphant@ee.byu.edu</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Timothy Hochberg wrote:<br>><br>><br>><br>> On 1/6/07, *Robert Kern* < <a href="mailto:robert.kern@gmail.com">robert.kern@gmail.com</a><br>> <mailto:<a href="mailto:robert.kern@gmail.com">robert.kern@gmail.com
</a>>> wrote:<br>><br>>     Sean R. Lynch wrote:<br>><br>>     >>>> x = zeros((3,))<br>>     >>>> x[array([0, 1, 1])] += array([1, 1, 1])<br>>     >>>> x<br>>     > array([ 1.,  1.,  0.])
<br>>     ><br>>     > If this worked the way I was hoping, the output would be [1 2 0]<br>>     because<br>>     > it would add to element 1 twice due to its duplication in the<br>>     advanced<br>
>     > selection array.<br>>     ><br>>     > Is the current behavior intentional or is it an accident of<br>>     > implementation?<br>><br>>     It is an unavoidable consequence of the way Python interprets that
<br>>     code and the<br>>     way numpy arrays are fundamentally implemented. See Travis<br>>     Oliphant's, Tim<br>>     Hochberg's and my posts in the thread "Histograms via indirect<br>>     index arrays" for
<br>>     more details.<br>><br>>     <a href="http://projects.scipy.org/pipermail/numpy-discussion/2006-March/thread.html#6877">http://projects.scipy.org/pipermail/numpy-discussion/2006-March/thread.html#6877</a>
<br>><br>><br>> Do we have to revisit that thread? I seem to recall it getting kind of<br>> cranky. To avoid reliving that, I will attempt dredge up the relevant<br>> issue:<br>><br>> "a[indx]+=b" should be the same as "a[indx]=a[indx]+b". All else
<br>> follow from that. If staring at that for a while doesn't enlighten<br>> you, then you will have to read that thread.<br>><br>> [ I suspect that in theory we could make the += form behave as you<br>> expect, but that would break the identity above, which would confuse a
<br>> bunch of people]<br>><br><br>I don't think we could make it work as he expects (and not radically<br>change NumPy itself so that other operations are very different) because<br>of the limitations of Python.
<br><br>The point was that it is too complicated to do any differently (and is<br>probably impossible).</blockquote><div><br>Right you are -- I was suffering a thinko -- sorry.<br><br>-tim <br></div><br></div><br>