Search code examples
pythonnumpyscipymathematical-optimization

Minimize function of many variables


I have the following code that defines the function f:

def f(a,b,lst,data): 
     #Evaluates some function that depends on parameters a, b, lst and data
     value = #some value calculation
     return value 

Where a,b are float, lst is list and data is np.array. I'm trying to minimize this function with respect to a,b using scipy.optimize.minimize, but when I run this

lst = #some list
data = #some np.array
scipy.optimize.minimize(f,x0 = [0.1,0.1], args = (lst,data))

I'm getting the following error: f() missing 1 required positional argument: 'data'


Solution

  • I think you are defining data outside the function already. Just delete the data object from the function and it will work perfectly.