[SciPy-User] bug in optimize.curve_fit ?

Xavier Gnata xavier.gnata@gmail....
Thu Aug 4 09:17:07 CDT 2011


Hi,

def func(x, a, b, c):
    return a*np.exp(-b*x) + c
x = np.linspace(0,4,50)
y = func(x, 2.5, 1.3, 0.5)
yn = y + 0.2*np.random.normal(size=len(x))
popt, pcov = curve_fit(func,x, yn)

works vey well but if you change it to:

def func(x, a, b, c):
    return a*np.exp(-b*x) + c
x = list(np.linspace(0,4,50))
y = func(x, 2.5, 1.3, 0.5)
yn = y + 0.2*np.random.normal(size=len(x))
popt, pcov = curve_fit(func, x, yn)

then x is a list and we get this error:
"TypeError: can't multiply sequence by non-int of type 'float'"

However, according to the documentation, xdata : An N-length sequence
or an (k,N)-shaped array. I understand this statement as : "either a
list, a tuple or an array". Should optimize.curve_fit internally cast
xdata to an array? I would think so.



Xavier


More information about the SciPy-User mailing list