From: Larry D. <la...@pa...> - 2002-05-28 20:03:28
|
Pearu Peterson said: > > On Tue, 28 May 2002, Larry Denneau wrote: > > > Hello, > > > > I recently discovered the following behavior when fetching values > > from a Numeric array. Can somebody offer some insight? > > > > #1) > > > > import Numeric > > > > a = Numeric.zeros((2, 2), 'i') > > n = a[1, 1] # fetch interesting value from array > > print n > > a[1, 1] = 10 # change array > > print n # blam > > print type(n) # huh > > > > [bash]$ python 1.py > > 0 > > 10 > > <type 'array'> [ deleted] > Use > > a[1][1] = 10 > > and the output will be > > 0 > 0 > <type 'int'> > > I find it is an useful feature in Numeric to have both behaviours of > either using a[1,1] or a[1][1]. You may want to dig into Numeric's > userguide to get a more detailed explanation of the differences. > > Regards, > Pearu Hi Pearu, I assume you mean n = a[1][1] which produces the expected behavior. All the Numpy documentation examples (see http://pfdubois.com/numpy/html2/numpy-6.html#pgfId-36033, "Getting and Stting Array Values") use the [x, y] notation instead of [x][y], so I would consider this a bug in the documentation, since the [x, y] method leads to unexpected behavior. I'm still curious what happens to the original array when n=a[1, 1] del(a) but that may have to wait until I have time to peruse the Numeric source. Thanks, Larry |