Re: dot products

2004-12-20 Thread Alan G Isaac
"Alan G Isaac" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > This times faster than the alternatives I have seen mentioned so far, > given scipy. Actually, since I am new to 'timeit', I probably should check that I am not overlooking something. Especially since I see an order of m

Re: dot products

2004-12-20 Thread Alan G Isaac
[Rahul]. > I want to compute dot product of two vectors stored as lists a and b.a > and b are of the same length from scipy import dot ans=dot(a,b) This times faster than the alternatives I have seen mentioned so far, given scipy. Cheers, Alan Isaac -- http://mail.python.org/mailman/listinfo/

Re: dot products

2004-12-20 Thread Raymond Hettinger
[Rahul]. > > 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 > > ans=0.0 > > for i in range(len(a)): > > ans=ans+a[i]*b[i] > > > > But is there

Re: dot products

2004-12-20 Thread John Lenton
On Sun, Dec 19, 2004 at 03:04:15AM -0800, Rahul wrote: > HI. > 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 > ans=0.0 > for i in range(len(a)): > ans=a

Re: dot products

2004-12-19 Thread Bengt Richter
On 19 Dec 2004 03:04:15 -0800, "Rahul" <[EMAIL PROTECTED]> wrote: >HI. >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 >ans=0.0 >for i in range(len(a)): >ans=

Re: dot products

2004-12-19 Thread Rahul
Raymond Hettinger wrote: > [Rahul]. > > 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 > > ans=0.0 > > for i in range(len(a)): > > ans=ans+a[i

Re: dot products

2004-12-19 Thread Fredrik Lundh
Raymond Hettinger wrote: > * applying itertools instead of genexps can save the eval-loop overhead > * however, genexps are usually more readable than itertools solutions I'm still waiting for you to implement itertools as a parse-tree analyzer/code generator, rather than an "bare" extension mod

Re: dot products

2004-12-19 Thread Raymond Hettinger
[Rahul]. > 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 > ans=0.0 > for i in range(len(a)): > ans=ans+a[i]*b[i] > > But is there any other way which is f

Re: dot products

2004-12-19 Thread Steven Bethard
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. . >>> import numarray as na . >>> a, b = na.arange(5), na.arange(5, 10) . >>> na.dot(a, b) . 80 Steve -- http://mail.python.org/mailman/listinfo/python-list

Re: dot products

2004-12-19 Thread Peter Otten
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))) > > another simple way is > ans=0.0 > for i in range(len(a)): > ans=ans+a[i]*b[i] > > But is there any other way wh

Re: dot products

2004-12-19 Thread Nick Coghlan
Rahul wrote: HI. 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 ans=0.0 for i in range(len(a)): ans=ans+a[i]*b[i] But is there any other way which is faster than any o

Re: dot products

2004-12-19 Thread Andrey Tatarinov
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)) -- http://mail.python.org/mailman/listinfo/python-list

dot products

2004-12-19 Thread Rahul
HI. 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 ans=0.0 for i in range(len(a)): ans=ans+a[i]*b[i] But is there any other way which is faster than any of the abov