Scipy 最小化 fmin - 语法问题 [英] Scipy minimize fmin - problems with syntax
问题描述
我有一个函数,它接受多个参数(一个数组和两个浮点数)并返回一个标量(浮点数).现在我想通过改变两个参数来最小化这个函数:两个浮点数.数组在函数内部解包",然后使用其内容(数组和浮点数).
I have a function which takes several arguments (one array and two floats) and returns a scalar (float). Now I want to minimize this function by varying two of the arguments: the two floats. The array is "unpacked" inside the function at its contents (arrays and floats) are then used.
如何使用 SciPy 的 fmin 函数完成此操作?我很难为此找出正确的语法..
How can this be done using SciPy's fmin function? I am having a very hard time figuring out the right syntax for this..
函数类似于:
def func(x, y, data)
data1=data[0]
data2=data[...]
...
...
result = ...x...y...data1...data2... #result is a scalar (float)
return result
在这种情况下 scipy.optimize.fmin
应该是什么样子?
What should scipy.optimize.fmin
look like in this case?
optimize.fmin(func, ???)
非常感谢!
一切顺利,p.p.
推荐答案
scipy
假定参数在一个数组中.你可以定义一个辅助函数:
scipy
assumes that the arguments are in an array. You can define a helper function:
def helper(xy):
return func(xy[0], xy[1], data)
并使用 optimize.fmin
将其最小化:
and minimize it with optimize.fmin
:
optimize.fmin(helper, np.array([x0, y0]), ...)
这篇关于Scipy 最小化 fmin - 语法问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!