[SciPy-User] bug in optimize.curve_fit ?
Oleksandr Huziy
guziy.sasha at gmail.com
Thu Aug 4 10:26:23 EDT 2011
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 at 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 at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20110804/7dee78e9/attachment.html>
More information about the SciPy-User
mailing list