Currently I have a program that finds the dot product of two XYZ coordinates, how would I put this into a loop, so that it goes down a list of coordinates and finds the dot prod
import operator
vector1 = (1, 2, 3)
# get a list of vectors
vectors = [
(4, 5, 6),
(7, 8, 9)
]
# for loop through the vectors,
# assignig the current vector to vector2 in every iteration
for vector2 in vectors:
dotProduct = reduce(operator.add, map(operator.mul, vector1, vector2))
print dotProduct
Using your l, nat and a variables:
vector1 = (int(l[0][0]), int(l[0][1]), int(l[0][2]))
for a in range(1, nat):
vector2 = (int(l[a][0]), int(l[a][1]), int(l[a][2]))
dotProduct = reduce(operator.add, map(operator.mul, vector1, vector2))
print(dotProduct)