dot products

Rahul codedivine at
Sun Dec 19 12:04:15 CET 2004

I want to compute dot product of two vectors stored as lists a and b.a
and b are of the same length.

one simple way is
sum(a[i]*b[i] for i in range(len(a)))

another simple way is
for i in range(len(a)):

But is there any other way which is faster than any of the above. (By
the way profiling them i found that the second is faster by about 30%.)

More information about the Python-list mailing list