Hi all,
I am trying to rewrite the following code, to avoid having to write 60 individual loops,I would really appreciate your help with this.
# Long Version - not ideal
num = 60
n = [open('n%i.txt' % i, "w") for i in range (num)]
for a2s1, a2s0, a1s1, a1s0 in zip(c2v1.values, c2v0.values, c1v1.values, c1v0.values):
m = sqrt((((a2s1.data-a2s0.data)**2))+((a1s1.data**2-a1s0.data)**2))
n[2].write(('%6.20f\n') % (m))
for a2s1, a2s0, a1s1, a1s0 in zip(c2v2.values, c2v1.values, c1v2.values, c1v1.values):
m = sqrt((((a2s1.data-a2s0.data)**2))+((a1s1.data**2-a1s0.data)**2))
n[1].write(('%6.20f\n') % (m))
:
for a2s1, a2s0, a1s1, a1s0 in zip(c2v60.values, c2v59.values, c1v60.values, c1v59.values):
m = sqrt((((a2s1.data-a2s0.data)**2))+((a1s1.data**2-a1s0.data)**2))
n[60].write(('%6.20f\n') % (m))
# Way of improving the code above (my attempt)
num = 60
n = [open('n%i.txt' % i, "w") for i in range (num)]
for i in range(num)
for a2s1, a2s0, a1s1, a1s0 in zip(c2v(i+1).values, c2v(i).values, c1v(i+1).values, c1v(i).values):
m = sqrt((((a2s1.data-a2s0.data)**2))+((a1s1.data**2-a1s0.data)**2))
n[i+1].write(('%6.20f\n') % (m))
Is there anything wrong with the code, or could I improve this?
Thanks