From: David C. <da...@ar...> - 2006-10-18 10:59:31
|
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. I understand that if foo is a numpy array, doing bar = foo makes no copy, and whenever you change the value of foo, you change the value of bar: import numpy as N foo = N.linspace(0, 4, 5) bar = foo print foo[1] bar[1] = -1 print foo[1] => prints 1 and -1. 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 ? Cheers, David |