I have seen this question or a variant asked elsewhere e.g.
Scipy error using optimization module. Failure converting array to fortran
http://numpy-discussio
Hi I had the same error with the following:
def ptf_returns(weights,returns):
return pd.DataFrame(np.array(returns).T*(weights)).T.mean().mean()
When I add the following it works:
def ptf_returns(weights,returns):
return float(pd.DataFrame(np.array(returns).T*(weights)).T.mean().mean())
The bug seems to be oriented around the type()
of the response.
I get the same error when the return from the Objective function is not a scalar. A minimal example which causes this error is
from scipy.optimize import fmin_slsqp
def fn(x):
return [0.,1.]
x = [0, 1., 2.]
minsoln = fmin_slsqp(fn, x)
while the following does not raise the error,
from scipy.optimize import fmin_slsqp
def fn(x):
return 0.
x = [0, 1., 2.]
minsoln = fmin_slsqp(fn, x)
I think this is either a bug or should have a clearer error message. I've raise an issue.
UPDATE:
This has now been resolved by b-carter to give a clear error message,
"Objective function must return a scalar"
with the documentation updated, see this thread for discussion.