can't assign value to array element

Terry Reedy tjreedy at udel.edu
Mon Nov 4 00:45:43 EST 2002


"Joe Heafner" <heafnerj at spam.vnet.net> wrote in message
news:HoCdnRcDleGnR1igXTWcqg at ctc.net...
> y = zeros(m, Float)

y is now array of m 0.0

> y[0] = b

reset first value to b
>
> for j in range(0,m,1):
...
>     y = y[j]

y is now a float.  This cannot be what you meant to do

>     y[j+1] = y+(k1+2.*k2+2.k3+k4)/6.

cannot index a float, hence message

> When run, this code give the error "TypeError: object does not
support
> item assignment" for hte next to last line. I presume the last line
would
> give the same error.

Yes, but only because you did same thing of rebinding name 't' to a
float.

> What am I doint wrong? I'd appreciate any  help.

Figure out what really want to do with t and y.  I suspect you want
tj = t[j]
yj= y[j]
and use tj and jy in code that follows in loop.

Terry J. Reedy





More information about the Python-list mailing list