def VerletNextV(v_t,a_t,a_t_plus_h):
v_t_plus_h = [0.0, 0.0, 0.0]
#<-- find v_t_plus_h[0], v_t_plus_h[1], v_t_plus_h[2], here -->
for i in range(0,len(v_t_plus_h)):
v_t_plus_h[i] = v_t + .5*(a_t[i] + a_t_plus_h[i])
return v_t_plus_h
Next I have this line:
nV[i] = VerletNextV(V[i],A[i], a_t_h)
which is giving me the error that I specified in my title:
ValueError: setting an array element with a sequence
This is driving me insane - what is the problem here? nV[i]
is a declared using:
nV = numpy.zeros((N,3))
V[i],A[i], a_t_h
? – Marcin Feb 16 at 23:46VerletNextV
is actually returning. If it is returning a list of 3 numbers then this should work, but it seems likely that is is probably not. – Iguananaut Feb 16 at 23:48v_t_plus_h = []
and usev_t_plus_h.append
in the loop. Or use a list comprehension. Though since it seems like you're doing vector arithmetic it might make more sense if you velocity and acceleration vectors were also Numpy arrays; then you would just array arithmetic and no explicit loops in Python. – Iguananaut Feb 16 at 23:52numpy
array, and then filling it row by row is a valid approach. Building an array from a comprehension is also good. That is, if you can't do it with vector operations. – hpaulj Feb 17 at 3:09nV[i,:] = VerletNextV(V[i],A[i], a_t_h)
. You could also print the shape of both sides of that equation before hand. The error looks likenV[i]
is a scalar, andVerletNextV()
is a list. – hpaulj Feb 17 at 3:16