[Numpy-discussion] Numpy array performance issue
Bruno Santos
bacmsantos@gmail....
Wed Feb 24 10:21:46 CST 2010
>
>
>
> The idiomatic way of doing this for numpy arrays would be:
>
> def test2(arrx):
> return (arrx >= 10).sum()
>
> Even this versions takes more time to run than my original python version
> with arrays.
>>> def test3(listx):
... return (listx>=10).sum()
>>> t = timeit.Timer("test3(list2)","from __main__ import *")
>>> t.timeit()
7.146049976348877
My fastest version at the moment is:
def test3(listx):
... return len(numpy.where(listx>=10)[0])
>>> t = timeit.Timer("test3(list2)","from __main__ import *")
<timeit-src>:2: SyntaxWarning: import * only allowed at module level
>>> t.timeit()
5.8264470100402832
Thank you. All the best,
Bruno
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/numpy-discussion/attachments/20100224/ddde02bb/attachment.html
More information about the NumPy-Discussion
mailing list