[Numpy-discussion] which one is best?
lorenzo
lbolla@gmail....
Fri Sep 19 09:09:11 CDT 2008
On Fri, Sep 19, 2008 at 2:50 PM, Arnar Flatberg <arnar.flatberg@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://projects.scipy.org/pipermail/numpy-discussion/attachments/20080919/2194cd1a/attachment.html
More information about the Numpy-discussion
mailing list