From: Sven S. <sve...@gm...> - 2006-10-18 11:47:44
|
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 |