Does this Python code actually find the dot product of two vectors?
import operator
vector1 = (2,3,5)
vector2 = (3,4,6)
dotProduct = reduce( operator.add, map( operator.mul, vector1, vector2))
Yes it does. Here is another way
>>> sum(map( operator.mul, vector1, vector2))
48
and another that doesn't use operator
at all
>>> vector1 = (2,3,5)
>>> vector2 = (3,4,6)
>>> sum(p*q for p,q in zip(vector1, vector2))
48