Array assigment with Numeric.py
Morris, Brad [WDLN2:2W40:EXCH]
confused at americasm01.nt.com
Tue May 30 11:02:38 EDT 2000
Hi,
Re: Python 1.52 with Numerical.py
I'm having difficulty with the assignment of an array
based value to another array based value. The error
message is approximately "array shapes don't match".
I suspect it has to do with the way arrays are stored
and the way assignment is treated (i.e. if c is an
array then a = c simply makes 'a' point to 'c' it does
not make a new copy) but I don't fully understand how
to get what I want.
Simple example:
c = array([[1.0, 2.0, 3.0, 4.0],[5.0, 6.0, 7.0 8.0]])
c.shape
(2,4)
d = array([9.0, 11.0, 3.0, 12.0, 15.0, 20.0])
d.shape
(1,6)
temp = d[0] * d[5]
c[0,0] = temp
c[0,0] = d[0] * d[5]
So temp == 180 as expected and has a shape of (1,) but
the subsequent 2 lines fail with an error message along
the lines of "array shapes don't match". Both the right
and left halves of the last two lines represent a single
value but somehow the underlying shape is getting in the
way. Coming from a long history of Matlab use is probably
not helping me!
How do I force (coerce?) the right hand argument in to
the left?
Regards,
Brad
More information about the Python-list
mailing list