Scipy curve_fit多个数据系列 [英] Scipy curve_fit multiple series of data

查看:343
本文介绍了Scipy curve_fit多个数据系列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试建立一条曲线拟合,该曲线将基于x的相同值和相同(指数)定律的y的多个序列考虑在内.该系列中的y值由于处于实验状态而略有不同,但仍很接近(相同的x).

我尝试构建两个数组:一个带有x,一个带有两个不同的y系列


I'm trying to have a curve fit that takes into account multiple series of y based on same values of x and same (exponential) law. The y values among the series vary a little since they're experimental but are still close (at same x).

I tried to build two arrays: one with the x and one with the two different series of y

def f(x,a,b,c):
    return a*numpy.exp(-b*x)+c
xdata=numpy.array([data['x'],data['x']])
ydata = numpy.array([data['y1'], data['y2']])
popt, pcov=curve_fit(f,xdata,ydata)

但是出现此错误:

TypeError: Improper input: N=3 must not exceed M=2

有人知道如何解决该错误或进行这种曲线拟合的正确方法吗?

Does anyone know how solve this error or a proper way to do this kind of curve fitting?

推荐答案

您应 concatenate 正确地处理数据,而不是创建多维数组. curve_fit 中没有任何内容指出数据必须按x排序:

xdata = np.concatenate((data['x'], data['x']))
ydata = np.concatenate((data['y1'], data['y2']))
popt, pcov = curve_fit(f, xdata, ydata)

这假定data的引用元素都是一维的.

This assumes that the referenced elements of data are all 1D.

这篇关于Scipy curve_fit多个数据系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆