Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

As for the else statement, this is probably faster:

else:
    return numpy.array([simplefunc(xx) for xx in x])

As for the else statement, this is probably faster:

else:
    return numpy.array([simplefunc(xx) for xx in x])

I probably wouldn't even put that in an else statement either. Just put it as the last line of the function.

As for the else statement, this is probably faster:

else:
    return numpy.array([simplefunc(xx) for xx in x])

I probably wouldn't even put that in an else statement either. Just put it as the last line of the function.

Update

It looks like map is slightly faster than a list comprehension in the test below:

sage: def f(x): return x*x
....: 
sage: timeit('map(f,xrange(1e6))')
5 loops, best of 3: 223 ms per loop
sage: timeit('[f(x) for x in xrange(1e6)]')
5 loops, best of 3: 277 ms per loop