questions regarding assignement and copy

Travis Oliphant oliphant.travis at
Wed Oct 18 12:16:17 CDT 2006

David Cournapeau wrote:
> Sven Schreiber wrote:
>> Yes it's intended; as far as I understand the python/numpy syntax, <+>
>> is an operator, and that triggers assignment by copy (even if you do
>> something trivial as bar = +foo, you get a copy, if I'm not mistaken),
> So basically, whenever you have
> foo = expr
> with expr is a numpy expression containing foo, you trigger a copy ?

I think you are better off understanding that "=" is a name binding 
operation while "+=" calls a special method that allows in-place adding.


bar += foo


bar.__iadd__(bar, foo)

which gives the opportunity to add foo to bar in-place


bar = bar + foo

adds bar to foo (which results in a new array that then gets re-bound to 
the name bar).

The '=' sign is not an operator.  Perhaps this will help you see the 
difference.  It's good to know what kinds of things trip people up.  We 
can target tutorials and FAQs to those things.


Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo

More information about the Numpy-discussion mailing list