1

I'm working with a function, scipy.optimize.fmin_bfgs, which has several output variables. I care about two of them, xopt and fopt. How do I store these variables? The following isn't working for me:

xopt, fopt = fmin_bfgs(f, 0, fprime = fprime)

However, this gives me fopt:

fopt = fmin_bfgs(f, 0, fprime = fprime)

I need xopt too, but it says that I "need 1 more value to unpack."

1 Answer 1

2

You need to set full_output to true, after which fopt, func_calls, grad_calls, and warnflag are included too; you can slice the returned sequence:

xopt, fopt = fmin_bfgs(f, 0, fprime = fprime, full_output=True)[:2]

See the scipy.optimize.fmin_bfgs documentation:

full_output : bool, optional
If True,return fopt, func_calls, grad_calls, and warnflag in addition to xopt.

Granted, the documentation for this function makes this far from obvious, I first had to look at the linked source code. By the looks of it, bopt and gopt are also included when full_output is set, but the documentation fails to properly explain this.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.