简体   繁体   English

Scipyoptimize.fmin错误的返回值

[英]Scipy optimize.fmin wrong return values

I am currently using scipy.optimize.fmin() function and I am experiencing a problem with it. 我目前正在使用scipy.optimize.fmin()函数,但遇到了问题。 When I look at the documentation it says: 当我查看文档时,它说:

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.

But when I try this: 但是当我尝试这个:

res, min = opt.fmin(optim, self._params, (param_optim, self._paramsIni, Qmes, critere_efficacite, self, codeBV, interval), maxiter=5)

I get this error: 我收到此错误:

ValueError: too many values to unpack (expected 2)

Anyone has an idea why? 有人知道为什么吗? I mean is the documention wrong (I guess not) or am I doing something wrong? 我的意思是文档错误(我猜没有)还是我做错了什么? I am using scipy 0.19 and Python34 我正在使用scipy 0.19和Python34

Thanks in advance. 提前致谢。

To be slightly more exact: The function returns either a tuple of 6 values ( 更精确一点:该函数返回6个值的元组(

full_output : bool, optional Set to True if fopt and warnflag outputs are desired. full_output:bool,可选如果需要fopt和warnflag输出,则设置为True。

) or one (if it is left at False which is the default). )或一个(如果保留为False ,则为默认值)。 If you want to have only the second value of the full output, I recommend you set full_output=True and pattern-match as suggested in the comments. 如果只希望完整输出的第二个值,建议您按照注释中的建议设置full_output=True和pattern-match。 Alternativly you can store the result in one tuple res = opt.fmin(<your arguments>) and then access r=res[0] min=res[1] . 另外,您可以将结果存储在一个元组中res = opt.fmin(<your arguments>) ,然后访问r=res[0] min=res[1]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM