(python 2) I have this code that takes my arrays, x1,y1,z1, vx1, vy1,vz1, and operates on them (this is the bulk of the code), and at the end I'm left with new arrays x2,y2,z2, vx2,vy2,vz2. What I want to do is figure out how to loop the whole code, but update x1,y1,...etc with x2,y2,... giving me x3,y3.... etc until I have xn,yn,... etc.
I tried to do this by using,
for timestep in xrange(0,1000):
but this just runs the whole program 1000 times giving me x2,y2,... 1000 times. In addition, it's really slow. However, what I want to do is get x1000,y1000,.... preferably using Numpy so my code also runs more quickly.
#x1,y1,z1,vx1,vy1,vz1,mass1,and n1 are all arrays with npoints elements
for timestep in xrange(0,1000):
M = np.zeros((npoints,npoints))
def do_work(xn, step):
#Not my actual function, but to give you an idea
M[xn,step] = x1[step]+y1[step]+z1[step]+x1[xn]+y[xn]+z[xn]
#the rest of this is all just more code to create my new arrays.
[do_work(xn, step) for (xn,step) in itertools.product(xrange(npoints), xrange(npoints))]
a=[np.sum(arr) for arr in M]
a = np.array(a)
vxx = np.array(vx1)
vyy=np.array(vy1)
vzz=np.array(vz1)
vx=vxx[0:npoints]
vy=vyy[0:npoints]
vz=vzz[0:npoints]
vx2 = vx + (a +a)/2 * dt
vy2 = vy + (a +a)/2 * dt
vz2 = vz + (a+a)/2 * dt
xx = np.array(x1)
yy = np.array(y1)
zz = np.array(z1)
x=xx[0:npoints]
y=yy[0:npoints]
z=zz[0:npoints]
x2= (x+vx2*dt) + (a*dt**2)/2
y2= (y+vy2*dt) + (a*dt**2)/2
z2= (z+vz2*dt) + (a*dt**2)/2
#plotting and printing
#print x1
#plt.scatter(x2,y2)
plt.show()