简体   繁体   English

Scipy curve_fit多个数据系列

[英]Scipy curve_fit multiple series of data


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. 我正在尝试让曲线拟合考虑到基于x的相同值和相同(指数)定律的y系列。 The y values among the series vary a little since they're experimental but are still close (at same x). 该系列中的y值由于处于实验状态而略有不同,但仍很接近(相同的x)。

I tried to build two arrays: one with the x and one with the two different series of y 我试图建立两个数组:一个带有x,一个带有两个不同的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)

But this error appears: 但是出现此错误:

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? 有谁知道如何解决该错误或进行这种曲线拟合的正确方法?

You should concatenate the data properly instead of creating a multi-dimensional array. 您应该正确地concatenate数据,而不是创建多维数组。 There is nothing in curve_fit that states that the data has to be sorted by x : curve_fit中没有任何curve_fit表明必须按x排序数据:

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

This assumes that the referenced elements of data are all 1D. 假定data的引用元素均为1D。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM