From: Robert K. <rob...@gm...> - 2006-10-08 22:59:32
|
Bill Baxter wrote: > Yes, that'd be > a[b] += c No, I'm afraid that fancy indexing does not do the loop that you are thinking it would (and for reasons that we've discussed previously on this list, *can't* do that loop). That statement reduces to something like the following: tmp = a[b] tmp = tmp.__iadd__(c) a[b] = tmp In [1]: from numpy import * In [2]: a = array([0, 0]) In [3]: b = array([0, 1, 0, 1, 0]) In [4]: c = array([1, 1, 1, 1, 1]) In [5]: a[b] += c In [6]: a Out[6]: array([1, 1]) In [7]: a = array([0, 0]) In [8]: tmp = a[b] In [9]: tmp Out[9]: array([0, 0, 0, 0, 0]) In [10]: tmp = tmp.__iadd__(c) In [11]: tmp Out[11]: array([1, 1, 1, 1, 1]) In [12]: a[b] = tmp In [13]: a Out[13]: array([1, 1]) -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco |