I have an array farr of functions, say
import numpy as np
farr=np.array([(lambda x, y: x+y) for n in range(5)])
(in reality, the functions are all different splines)
Now, I would like one function f that returns the result of all the functions in farr as an array. Basically this:
def f(x, y):
return np.array([f(x, y) for f in farr])
Can this be done in a more efficient way?
farris a list instead of an array it should iterate a bit faster.frompyfuncoften provides a modest improvement over iteration (up to 2x). A possible use:fn=np.frompyfunc(lambda f,x,y:f(x,y),3,1), andfn(farr[:,None],x,y).