Parallel arithmetic?

Cyril Bazin cyril.bazin at
Fri Aug 5 01:07:34 CEST 2005


I propose 3 solutions. If someone have time to waste, he can make a 
benchmark to know which is the fastest and give us the results on the list. 

Solution 1:

import itertools
c = [a_i-b_i for a_i, b_i in itertools.izip(a, b)]

Solution 2:

c = map(operator.sub, a, b)
#"map" will be removed from the next versions of python. So, it's not a good 

Solution 3:

import itertools
c = list(itertools.imap(operator.sub, a, b))

These solutions give you a list. Depending on your usage, an iterator can be 


On 04 Aug 2005 15:41:28 -0700, Paul Rubin <""@nospam.invalid> 
> "Terrance N. Phillip" <mediocre_person at> writes:
> > Given a and b, two equal length lists of integers, I want c to be
> > [a1-b1, a2-b2, ... , an-bn].
> c = [a[i] - b[i] for i in xrange(len(a))]
> --
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the Python-list mailing list