[Numpy-discussion] MA : assignment to slices doesn't work like Numeric.

Paul F. Dubois paul at pfdubois.com
Mon Jul 9 13:01:35 CDT 2001


It is an advertised difference between MA and Numeric that index operations
return copies, not references.

-----Original Message-----
From: numpy-discussion-admin at lists.sourceforge.net
[mailto:numpy-discussion-admin at lists.sourceforge.net]On Behalf Of Joe
Van Andel
Sent: Thursday, June 28, 2001 3:42 PM
To: numpy-discussion
Subject: [Numpy-discussion] MA : assignment to slices doesn't work like
Numeric.


I retrieved the latest MA from CVS.  I've noticed that assigning to a
slice doesn't work the same as Numeric.

Here's a simple test program:
--------------------------------
from MA import *
#from Numeric import *

numBeams,numGates = (5,4)
result = ones((numBeams, numGates),'f') * -327.68
print 'result = ', result
t1 = ones((numGates,),'f')
t2 = 2* ones((numGates,),'f')
result[0] = t1
result[1][:] = t2
print 'result = ', result
-----------------------------------------

Output using 'MA':
result =  [[-327.68,-327.68,-327.68,-327.68,]
 [-327.68,-327.68,-327.68,-327.68,]
 [-327.68,-327.68,-327.68,-327.68,]
 [-327.68,-327.68,-327.68,-327.68,]
 [-327.68,-327.68,-327.68,-327.68,]]
result =  [[   1.  ,   1.  ,   1.  ,   1.  ,]
 [-327.68,-327.68,-327.68,-327.68,]
 [-327.68,-327.68,-327.68,-327.68,]
 [-327.68,-327.68,-327.68,-327.68,]
 [-327.68,-327.68,-327.68,-327.68,]]

However, if I use Numeric, rather than MA, I get:
result =  [[-327.68 -327.68 -327.68 -327.68]
 [-327.68 -327.68 -327.68 -327.68]
 [-327.68 -327.68 -327.68 -327.68]
 [-327.68 -327.68 -327.68 -327.68]
 [-327.68 -327.68 -327.68 -327.68]]
result =  [[   1.      1.      1.      1.  ]
 [   2.      2.      2.      2.  ]
 [-327.68 -327.68 -327.68 -327.68]
 [-327.68 -327.68 -327.68 -327.68]
 [-327.68 -327.68 -327.68 -327.68]]


So,
a[x][:] = my_array

doesn't seem to work using 'MA'.

--
Joe VanAndel
National Center for Atmospheric Research
http://www.atd.ucar.edu/~vanandel/
Internet: vanandel at ucar.edu

_______________________________________________
Numpy-discussion mailing list
Numpy-discussion at lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/numpy-discussion





More information about the Numpy-discussion mailing list