[SciPy-User] Indexing question

Robert Kern robert.kern at gmail.com
Wed Aug 12 14:55:19 EDT 2009


On Mon, Aug 10, 2009 at 17:50, Dav Clark<dav at alum.mit.edu> wrote:
> This actually points out an obscure feature, which
> is that even if you have entries that are doubly (or n-ably)
> referenced in your indexing, each element in the lvalue will only get
> operated on once.  Thus, while I might have expected the following to
> yield a = [2, 0], it actually yields a = [1, 0]:
>
> a = array([0, 0])
> a[a] += 1 # a[0] incremented twice?  No!
>
> In other words, we don't need to worry about double-counting in our
> lvalues, which I guess is OK.  It'd be a bit more intuitive for _me_
> the other way 'round.  Any logic behind that, or perhaps just
> implementational ease?

Hard limit imposed by the semantics of +=, as discussed several times
previously on this list.

-- 
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



More information about the SciPy-User mailing list