[Numpy-discussion] (Late) summary of PEP-225 discussion at Scipy

David Warde-Farley dwf at cs.toronto.edu
Wed Oct 29 19:37:56 EDT 2008


On 29-Oct-08, at 3:43 PM, Robert Kern wrote:

> Eh, that's not entirely true.
>
>  x = 1
>  x += 2
>
> That's not in-place. They are called "augmented assignments", not
> "in-place operations" for this reason. The defining characteristic is
> that "x <op>= y" should be equivalent to "x = x <op> y" except
> possibly for *optional* in-place semantics.

Indeed.

x = "foo"
x += "bar"

This definitely isn't in-place, since strings are immutable, but it  
works, and people expect it to work.

Of course it's worth mentioning in the docs somewhere that only the  
augmented assignments for element-wise ops are in-place (which should  
be obvious to anyone who knows what an outer product is).

David



More information about the NumPy-Discussion mailing list