List comprehension, map, and numpy.vectorize performance

Posted by mcstrother on Stack Overflow See other posts from Stack Overflow or by mcstrother
Published on 2010-04-24T05:16:33Z Indexed on 2010/04/24 6:03 UTC
Read the original article Hit count: 169

Filed under:
|

I have a function foo(i) that takes an integer and takes a significant amount of time to execute. Will there be a significant performance difference between any of the following ways of initializing a:

a = [foo(i) for i in xrange(100)]

a = map(foo, range(100))

vfoo = numpy.vectorize(foo)
a = vfoo(range(100))

(I don't care whether the output is a list or a numpy array.)

Is there a better way?

© Stack Overflow or respective owner

Related posts about python

Related posts about numpy