Re: Efficient way to sum a product of numbers...

2009-08-31 Thread Jan Kaliszewski
31-08-2009 o 22:28:56 Jan Kaliszewski wrote: >>> setup = "from itertools import starmap, imap ; from operator import mul; import random, string; names = [rndom.choice(string. ascii_letters) for x in xrange(1)]; hours = [random.randint( 1, 12) for x in xrange(1000)]; m = zip(names, hours); w

Re: Efficient way to sum a product of numbers...

2009-08-31 Thread Jan Kaliszewski
31-08-2009 o 18:19:28 vsoler wrote: Say m= [[ 'a', 1], [ 'b', 2],[ 'a', 3]] r={'a':4, 'b':5, 'c':6} What I need is the calculation 1*4 + 2*5 + 3*4 = 4 + 10 + 12 = 26 That is, for each row list in variable 'm' look for its first element in variable 'r' and multiply

Re: Efficient way to sum a product of numbers...

2009-08-31 Thread Paul Rubin
vsoler writes: > m= [[ 'a', 1], [ 'b', 2],[ 'a', 3]] > r={'a':4, 'b':5, 'c':6} > > What I need is the calculation > > 1*4 + 2*5 + 3*4 = 4 + 10 + 12 = 26 sum(r[k]*w for k,w in m) -- http://mail.python.org/mailman/listinfo/python-list

Re: Efficient way to sum a product of numbers...

2009-08-31 Thread vsoler
On Aug 31, 6:59 pm, Tim Chase wrote: > vsoler wrote: > > On Aug 31, 6:30 pm, Tim Chase wrote: > >>> After simplifying my problem, I can say that I want to get the sum of > >>> the product of two culumns: > >>> Say > >>>          m= [[ 'a', 1], [ 'b', 2],[ 'a', 3]] > >> assuming you meant ['c', 3]

Re: Efficient way to sum a product of numbers...

2009-08-31 Thread Tim Chase
vsoler wrote: On Aug 31, 6:30 pm, Tim Chase wrote: After simplifying my problem, I can say that I want to get the sum of the product of two culumns: Say m= [[ 'a', 1], [ 'b', 2],[ 'a', 3]] assuming you meant ['c', 3] here...^> r={'a':4, 'b':5, 'c':6} What I need is the

Re: Efficient way to sum a product of numbers...

2009-08-31 Thread vsoler
On Aug 31, 6:30 pm, Tim Chase wrote: > > After simplifying my problem, I can say that I want to get the sum of > > the product of two culumns: > > > Say > >          m= [[ 'a', 1], [ 'b', 2],[ 'a', 3]] > > assuming you meant ['c', 3] here...    ^>          r={'a':4, 'b':5, 'c':6} > > > What I need

Re: Efficient way to sum a product of numbers...

2009-08-31 Thread Tim Chase
After simplifying my problem, I can say that I want to get the sum of the product of two culumns: Say m= [[ 'a', 1], [ 'b', 2],[ 'a', 3]] assuming you meant ['c', 3] here...^ r={'a':4, 'b':5, 'c':6} What I need is the calculation 1*4 + 2*5 + 3*4 = 4 + 10 + 12 =

Efficient way to sum a product of numbers...

2009-08-31 Thread vsoler
Hi, After simplifying my problem, I can say that I want to get the sum of the product of two culumns: Say m= [[ 'a', 1], [ 'b', 2],[ 'a', 3]] r={'a':4, 'b':5, 'c':6} What I need is the calculation 1*4 + 2*5 + 3*4 = 4 + 10 + 12 = 26 That is, for each row list in varia