I have to find the 2 input values for which the output value is minimized:
import pandas as pd
def calc_func(x1, x2):
var1 = pd.DataFrame([x1]).loc[0]
var2 = pd.DataFrame([x2]).loc[0]
y = var1-var2
return(y)
from scipy.optimize import minimize
x0 = [1,2,3]
res = minimize(calc_func,x0,x0, method='BFGS')
however this gives me the following error
ValueError: setting an array element with a sequence.
Which can be explained by the fact that the calculations with pandas dataframes use single numbers instead of arrays...
What is the best way to minimize my function?
Comments:
- Unfortunately it is not an option to completeley remove all pandas calculations from the function.