dot products

Andrey Tatarinov elephantum at dezcom.mephi.ru
Sun Dec 19 06:38:47 EST 2004


Rahul wrote:

> 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)))
> 

btw, imho the most "Pythonic" would be:

sum(i*j for (i,j) in zip(a,b))



More information about the Python-list mailing list