Re: vector addition

2010-06-07 Thread Dan Stromberg
On Mon, Jun 7, 2010 at 1:16 PM, Thomas Jollans wrote: > On 06/07/2010 07:45 PM, Dan Stromberg wrote: > > > Call me strange, but I regard this as a good place to use a functional > style - IE, to use reduce, and furthermore I regard this as a good example > of why reduce is useful for more than j

Re: vector addition

2010-06-07 Thread Thomas Jollans
his loops through the list three times, which can be slow. > > I'd like to have something like this: > count_a, count_b, count_c = > sum( (int(x[1]=='a',int(x[1]=='b',int(x[1]=='c') for x in l) > > I hesitate

Re: vector addition

2010-06-07 Thread Dan Stromberg
> >> But this loops through the list three times, which can be slow. >> >> I'd like to have something like this: >> count_a, count_b, count_c = >> sum( (int(x[1]=='a',int(x[1]=='b',int(x[1]=='c') for x in l) >> >

Re: vector addition

2010-06-05 Thread MRAB
ount_b, count_c = sum( (int(x[1]=='a',int(x[1]=='b',int(x[1]=='c') for x in l) I hesitate to use numpy array, because that will literally create and destroy a ton of the arrays, and is likely to be slow. If you want to do vector addition then numpy is the way to go

Re: vector addition

2010-06-05 Thread Chris Rebert
On Sat, Jun 5, 2010 at 6:20 PM, GZ wrote: > Hi, > > I am looking for a fast internal vector representation so that > (a1,b2,c1)+(a2,b2,c2)=(a1+a2,b1+b2,c1+c2). > > So I have a list > > l = ['a'a,'bb','ca','de'...] > > I want to count all items that start with an 'a', 'b', and 'c'. > > What I can d

vector addition

2010-06-05 Thread GZ
Hi, I am looking for a fast internal vector representation so that (a1,b2,c1)+(a2,b2,c2)=(a1+a2,b1+b2,c1+c2). So I have a list l = ['a'a,'bb','ca','de'...] I want to count all items that start with an 'a', 'b', and 'c'. What I can do is: count_a = sum(int(x[1]=='a') for x in l) count_b = sum(