I'm trying to better understand python optimization so this is a dummy case, but hopefully outlines my idea...
Say I have a function which takes two variables:
def func(param1, param2):
return some_func(param1) + some_const*(param2/2)
and I have arrays for param1 and param2 (of different lengths), at which I want the function to be evaluated, (some_func is an arbitrary function of param1) e.g.
param1 = np.array((1,2,3,4,5))
param2 = np.array((5,2,3,1,9, 9, 10))
I can evaluate over all parameter space by doing:
result = []
for p in param1:
result.append(func(p, param2))
result = np.asarray(result)
However, loops in Python are slower than array operations. Therefore, I wonder is there a way to achieve a 3D array which contains the results of func for all values in both param1 and param2 arrays?