# [SciPy-User] bug in optimize.curve_fit ?

Xavier Gnata xavier.gnata@gmail....
Fri Aug 5 02:29:08 CDT 2011

```Hi,

Yes but the doc (
http://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html
) claims that xdata can be "An N-length sequence or an (k,N)-shaped array"

IRL, I would not cast a array to a list to call optimize.curve_fit.
x = list(x) was only an easy way to write a short testcase based on the
exemple in the doc.

Xavier

> Hi,
>
> if you did x = list(x) it becomes a simple list, which cannot be
> multiplied by a number.
> don't do this.
>
> --
> Oleksandr Huziy
>
>
> 2011/8/4 Xavier Gnata <xavier.gnata@gmail.com
> <mailto:xavier.gnata@gmail.com>>
>
>     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
>     _______________________________________________
>     SciPy-User mailing list
>     SciPy-User@scipy.org <mailto:SciPy-User@scipy.org>
>     http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user

```