I currently have a list of velocities in an n-body system at 10,000 points in time. It is a three-dimensional array concerning n particles at t points in time in three spatial dimensions. For example, with three particles at two points in time, it is set up as
[[[vx1][vy1][vz1]
[vx2][vy2][vz2]
[vx3][vy3][vz3]]
[[vx1][vy1][vz1]
[vx2][vy2][vz2]
[vx3][vy3][vz3]]]
My end goal is to have an array like this:
[[[speed1]
[speed2]
[speed3]]
[[speed1]
[speed2]
[speed3]]]
But I can't get the velocity components to add quadratically while the number of particles is free to vary. I could do it with two particles like this:
# Takes all velocities and converts them to speeds
all_speeds=[]
for i in range(len(all_velocities)):
all_speeds.append([math.sqrt(all_velocities[i][0][0]**2\
+all_velocities[i][0][1]**2+all_velocities[i][0][2]**2)],\
[math.sqrt(all_velocities[i][1][0]**2+all_velocities[i][1][1]**2\
+all_velocities[i][1][2]**2)])
But I am unsure of how to extend it to n particles. My very end goal is to square the velocity array and then multiply it by the array of masses that I have to calculate the system's kinetic energy but I can't extend it to work for any input. Thanks.