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

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 =

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

2009-08-31 Thread vsoler
On Aug 31, 6:30 pm, Tim Chase python.l...@tim.thechases.com 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}

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 python.l...@tim.thechases.com 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,

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

2009-08-31 Thread Paul Rubin
vsoler vicente.so...@gmail.com 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 python.l...@tim.thechases.com wrote: vsoler wrote: On Aug 31, 6:30 pm, Tim Chase python.l...@tim.thechases.com 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],[

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

2009-08-31 Thread Jan Kaliszewski
31-08-2009 o 18:19:28 vsoler vicente.so...@gmail.com 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

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

2009-08-31 Thread Jan Kaliszewski
31-08-2009 o 22:28:56 Jan Kaliszewski z...@chopin.edu.pl 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 =