What is the most efficient way to map a function over a numpy array? The way I\'ve been doing it in my current project is as follows:
import numpy as np x
How about using numpy.vectorize.
import numpy as np x = np.array([1, 2, 3, 4, 5]) squarer = lambda t: t ** 2 vfunc = np.vectorize(squarer) vfunc(x) # Output : array([ 1, 4, 9, 16, 25])