`TypeError: minimize() got multiple values for argument 'method'`without *kwargs

Viewed 341

I know it's related to the other question through the site, but I can't figure out what is the problem.

from scipy.optimize import minimize
def fun1(x,Cnoi,M):
    return np.linalg.norm(Cnoi - np.matmul(M,x))**2

minimize(fun1, x0, Cnoi, M, method='SLSQP', bounds=bnds, constraints=cons)

returns

TypeError: minimize() got multiple values for argument 'method'

I don't understand what is the problem, since fun1 has three "positional" arguments.

1 Answers

From the doc string of minimize:

args : tuple, optional
    Extra arguments passed to the objective function and its
    derivatives (`fun`, `jac` and `hess` functions).

The args need to be a tuple. The following should work.

minimize(fun1, x0, (Cnoi, M), method='SLSQP', bounds=bnds, constraints=cons)
Related