import numpy as np
def f(x):
return (np.power(x,0.7))*np.sqrt(x + 1.0/np.power(np.pi,2.0))*np.sin(1.0/(x + 1.0/np.power(np.pi,2.0)))
f(0.1)
_values=np.random.rand(10**6)
vect_images=f(_values)
list_comp_images = [ f(myX) for myX in _values ]
map_images=list(map(f,_values))
%timeit vect_images=f(_values)
%timeit list_comp_images = [ f(myX) for myX in _values ]
%timeit map_images=list(map(f,_values))
list(map(f,np.array([1,2,3])))
np.array(map(f,np.array([1,2,3])))
vf=np.vectorize(f)
vf(_values)
https://docs.scipy.org/doc/numpy/reference/generated/numpy.vectorize.html The vectorize function is provided primarily for convenience, not for performance. The implementation is essentially a for loop.