本文介绍了用参数最小化功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
目前,我有以下代码定义了函数f
.
Currently I have the following code that defines the function f
.
a = #something
b = #something
c = #something
def f(x):
"""Evaluates some function that depends on parameters a, b, and c"""
someNumber = #some calculation
return someNumber
理想情况下,我会做def f(x, a, b, c)
,但是相对于x
,我正在将f
最小化,SciPy的优化工具箱不允许使用参数中的参数来最小化函数.就是说,我想对a, b
和c
的多个值运行我的最小化代码.有办法吗?
Ideally I would do def f(x, a, b, c)
, BUT I am minimizing f
with respect to x
and SciPy's optimization toolbox doesn't allow for one to minimize functions with parameters in the arguments. That said I would like to run my minimization code for multiple values of a, b
and c
. Is there a way I can do this?
推荐答案
您可以在args
from scipy.optimize import minimize
minimize(f, x0, args=(a, b, c))
这篇关于用参数最小化功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!