computing a weighted sum
fperez.net at gmail.com
Wed Mar 16 23:22:51 CET 2005
andreif at mail.dntis.ro wrote:
> Suppose I have a list of n floats x and a list of n floats w and I want
> to compute x*w + .. + x[n-1]*w[n-1].
> Is there some elegant expression (perhaps using lambda) to have it done
> in one statement ? As in :
> y = lambda x,w : ...
> I ask because the way I am doing it now :
> y = 0
> for i in range(0,n): y += x[i]*w[i]
> doesn't seem very pythonic :)
More information about the Python-list