在curve_fit
的手册中有这样的说法
The model function, f(x, ...). It must take the independent variable as the first argument and the parameters to fit as separate remaining arguments.
但是,我想将定义为类的方法用作模型函数:
def model_fun(self,x,par):
因此,如您所见,第一个参数不是自变量。有什么办法可以将类的方法用作 curve_fit 的模型函数
最佳答案
当然,创建一个实例并传递它的绑定(bind)方法:
class MyClass(object):
...
def model_fun(self,x,par): ...
obj = MyClass(...)
curve_fit(obj.model_fun, ...)
你可以找到关于绑定(bind)/未绑定(bind)/等的很好的解释。在 this question .
关于python - 类方法作为 scipy.optimize.curve_fit 的模型函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16543610/