can't assign value to array element
Joe Heafner
heafnerj at spam.vnet.net
Sun Nov 3 21:23:54 EST 2002
Hi.
In my attempt to seriously learn Python (2.2.1 running on Mac OS X), I've
been trying to code some simple numerical algorithms. Here is my code for
one routine:
a=0.
b=1.4
y0=0.
m=10
h = (b-a)/m
t = zeros(m, Float)
t[0] = a
y = zeros(m, Float)
y[0] = b
for j in range(0,m,1):
print j # for debugging purposes
t = t[j]
y = y[j]
k1 = h*fprimexy(t,y)
k2 = h*fprimexy(t+h/2., y+0.5*k1)
k3 = h*fprimexy(t+h/2., y+0.5*k2)
k4 = h*fprimexy(t+h, y+k3)
y[j+1] = y+(k1+2.*k2+2.k3+k4)/6.
t[j+1] = a+h*(j+1)
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. I'm very new to Python and haven't been able to find
documentation about htis specific problem, and I've been working
(literally) all day on this. What am I doint wrong? I'd appreciate any
help.
Thanks.
JH
More information about the Python-list
mailing list