[Numpy-discussion] Bug: extremely misleading array behavior
larryd at pangalactic.com
Tue May 28 11:03:38 EDT 2002
I recently discovered the following behavior when fetching values
from a Numeric array. Can somebody offer some insight?
a = Numeric.zeros((2, 2), 'i')
n = a[1, 1] # fetch interesting value from array
a[1, 1] = 10 # change array
print n # blam
print type(n) # huh
[bash]$ python 1.py
a = Numeric.zeros((2,), 'i')
n = a
a = 10
[bash]$ python 2.py
#2 works the way one would expect, and #1 does not (n changes).
They should at least both behave the same. :-) At a minimum, naive
use of arrays can lead to confusing or disastrous results, since
a single value fetched from an array can change behind your back.
It appears n is aliased into a, but preserves its value when a is
deleted (with del(a)). What happens to the "rest of" a?
I'm using Python 2.2, Numeric-21.0, on both Unix and Win32.
More information about the NumPy-Discussion