Array assigment with

Morris, Brad [WDLN2:2W40:EXCH] confused at
Tue May 30 11:02:38 EDT 2000


Re: Python 1.52 with

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]])
d = array([9.0, 11.0, 3.0, 12.0, 15.0, 20.0])
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?


More information about the Python-list mailing list