questions regarding assignement and copy

Sven Schreiber svetosch at gmx.net
Wed Oct 18 07:47:14 EDT 2006


David Cournapeau schrieb:
> Hi there,
> 
>     I've just managed to nail down a bug which took me nearly two whole 
> days to find: this is coming from an unexpected (at least from me) 
> behaviour of numpy.

You have all my sympathy, I tripped over something similar not too long
ago, so welcome to the club.

>     Now, if I do:
> 
>     bar   += 1
>     print bar is foo
> 
>     prints True
> 
>     But if I do bar = bar + 1, then bar is not a copy of foo anymore. Is 
> this intended ? This looks really confusing to me, and I would like to 
> know what the precise rules about copy vs alias are ?
>

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),
while <+=> is syntactically not really an operator. AFAIK it's sole
purpose is really to _not_ make a copy to save memory (well, it also
looks nice ;-).

You'll need somebody else to tell you the _precise_ rules, though...

-sven


-------------------------------------------------------------------------
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
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642




More information about the NumPy-Discussion mailing list