python - 类方法作为 scipy.optimize.curve_fit 的模型函数

标签 python scipy curve-fitting

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/

相关文章:

python - 如何在线程中使用 LoopingCall?

python - 使用Python3.2重新缩放图像

python - 如何在 Keras ImageDataGenerator 中应用 OpenCV 颜色图转换?

python - 使用参数作为 scipy.optimize.curve_fit 的边界

r - 何时选择 nls() 而不是 loess()?

php - 生成范围内所有可能的 MAC 地址

python - python中带有随机点的二维插值

python - 如何获取多个峰值下的面积值

python - statsmodels - 绘制拟合分布

matlab - 获取matlab中fit函数的函数句柄并分配fit参数