[Numpy-discussion] which one is best?

lorenzo lbolla at gmail.com
Fri Sep 19 10:09:11 EDT 2008


On Fri, Sep 19, 2008 at 2:50 PM, Arnar Flatberg <arnar.flatberg at gmail.com>wrote:

>
>
> I think
> [x*y for x in a for y in b]
> feels pythonic, however it has a surprisingly lousy performance.
>
>
This returns a len(x)*len(y) long list, which is not what you want.

This two methods seem equivalent:

In [16]: x = 100000 * [1]
In [17]: y = 100000 * [2]
In [18]: %timeit map(lambda a,b: a*b, x, y)
10 loops, best of 3: 31.4 ms per loop
In [19]: %timeit [xx*yy for xx,yy in zip(x,y)]
10 loops, best of 3: 30.4 ms per loop

L.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20080919/2194cd1a/attachment.html>


More information about the NumPy-Discussion mailing list