Scipy optimize.fmin 错误的 return 值
Scipy optimize.fmin wrong return values
我目前正在使用 scipy.optimize.fmin()
功能,但遇到了问题。当我查看文档时,它说:
Returns:
xopt : ndarray
Parameter that minimizes function.
fopt : float
Value of function at minimum: fopt = func(xopt).
iter : int
Number of iterations performed.
funcalls : int
Number of function calls made.
warnflag : int
1 : Maximum number of function evaluations made. 2 : Maximum number of iterations reached.
allvecs : list
Solution at each iteration.
但是当我尝试这个时:
res, min = opt.fmin(optim, self._params, (param_optim, self._paramsIni, Qmes, critere_efficacite, self, codeBV, interval), maxiter=5)
我收到这个错误:
ValueError: too many values to unpack (expected 2)
有人知道为什么吗?我的意思是文档是错误的(我想不是)还是我做错了什么?我正在使用 scipy 0.19 和 Python34
提前致谢。
更准确地说:函数 returns 是一个包含 6 个值的元组(
full_output : bool, optional
Set to True if fopt and warnflag outputs are desired.
) 或一个(如果保留在 False
,这是默认值)。如果您只想获得完整输出的第二个值,我建议您按照注释中的建议设置 full_output=True
和模式匹配。或者,您可以将结果存储在一个元组 res = opt.fmin(<your arguments>)
中,然后访问 r=res[0] min=res[1]
。
我目前正在使用 scipy.optimize.fmin()
功能,但遇到了问题。当我查看文档时,它说:
Returns:
xopt : ndarray
Parameter that minimizes function.
fopt : float
Value of function at minimum: fopt = func(xopt).
iter : int
Number of iterations performed.
funcalls : int
Number of function calls made.
warnflag : int
1 : Maximum number of function evaluations made. 2 : Maximum number of iterations reached.
allvecs : list
Solution at each iteration.
但是当我尝试这个时:
res, min = opt.fmin(optim, self._params, (param_optim, self._paramsIni, Qmes, critere_efficacite, self, codeBV, interval), maxiter=5)
我收到这个错误:
ValueError: too many values to unpack (expected 2)
有人知道为什么吗?我的意思是文档是错误的(我想不是)还是我做错了什么?我正在使用 scipy 0.19 和 Python34
提前致谢。
更准确地说:函数 returns 是一个包含 6 个值的元组(
full_output : bool, optional Set to True if fopt and warnflag outputs are desired.
) 或一个(如果保留在 False
,这是默认值)。如果您只想获得完整输出的第二个值,我建议您按照注释中的建议设置 full_output=True
和模式匹配。或者,您可以将结果存储在一个元组 res = opt.fmin(<your arguments>)
中,然后访问 r=res[0] min=res[1]
。