[SciPy-Dev] scipy.optimize.curve_fit does not work with single parameter function

Warren Weckesser warren.weckesser@enthought....
Tue Sep 28 07:12:33 CDT 2010


  On 9/28/10 5:16 AM, Daniele Nicolodi wrote:
> Hello,
>
> I copied the code of scipy.optimize.curve_fit into my data analysis code
> to use it on a not so recent versions of scipy available on my systems.
> However it does not work when I try to fit a simple function that has
> only one parameter, for example:
>
> def func(x, p1):
>      return x * p1
>
> The problem is that scipy.optimize.leastsq() returns a list of
> parameters values for cases where the function has more than one
> parameter it returns a tuple of parameters values, while in the case of
> one single parameters it returns a numpy scalar value.
>
> This causes an error in the curve_fit _general_function() and
> _weighted_general_function() where the target function is called:
>
> function(xdata, *params)
>
> This works only if params is a python list or tuple.
>
> Also the return value suffers from the same problem. If the target
> function has more than one parameter you get a parameters list,
> otherwise you get a scalar. It would be more consistent to return always
> a list, also because the covariance is always returned as a matrix.
>
> Please ignore this if that has been resolved in more recent version of
> scipy, I have acces to 0.7.2 (last available on debian sid).
>


This was fixed in 0.8; see http://projects.scipy.org/scipy/ticket/1204

Warren



More information about the SciPy-Dev mailing list