by AncientPC · 14y ago · 0 comments
You are given two vectors v1=(x1,x2,...,xn) and v2=(y1,y2,...,yn). The scalar product of these vectors is a single number, calculated as x1y1+x2y2+...+xnyn.
Haskell:
sum(zipWith (*) [1,2,3][3,2,1])
Python is not inherently functional, just supports a few convenience idioms. It has zip, but no zipWith. As a result you have to use list comprehension to perform the same: sum([x*y for (x,y) in zip([1,2,3][3,2,1])]) sum(map(operator.mul, [1,2,3], [3,2,1]))