Parallel arithmetic?
Cyril Bazin
cyril.bazin at gmail.com
Thu Aug 4 19:07:34 EDT 2005
Hello,
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.
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
better.
Cyril
On 04 Aug 2005 15:41:28 -0700, Paul Rubin <"http://phr.cx"@nospam.invalid>
wrote:
>
> "Terrance N. Phillip" <mediocre_person at hotmail.com> 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))]
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20050805/c5091a23/attachment.html>
More information about the Python-list
mailing list