1

Using scipy.optimize.curve_fit I'm trying to get a best fit function og 2 measured data series to a third measured data series, like f(x,y)=z, where x,y,z are the measured series.

The code goes:

def func_events_model(xy,a,b,c): return a*xy[0]+b*xy[1]+c events_array=numpy.array(events_list) Tin_array=numpy.array(Tin_list) barometer_array=numpy.array(barometer_list) events_array=events_array.reshape(720,1) Tin_barometer_array=numpy.array([[Tin_list],[barometer_list]]) Tin_barometer_array=Tin_barometer_array.T popt_model,stats_model=curve_fit(func_events_model,Tin_barometer_array,events_array) 

I get this error message:

Traceback (most recent call last): File "DUKS_dataplot.py", line 100, in <module> popt_model,stats_model=curve_fit(func_events_model,Tin_barometer_array,events_array) File "/usr/lib/python2.7/dist-packages/scipy/optimize/minpack.py", line 506, in curve_fit res = leastsq(func, p0, args=args, full_output=1, **kw) File "/usr/lib/python2.7/dist-packages/scipy/optimize/minpack.py", line 355, in leastsq gtol, maxfev, epsfcn, factor, diag) minpack.error: Result from function call is not a proper array of floats. 

Any ideas to handle this? Or a better way to find best fit of f(x,y)=z?

The documentation for scipy.optimize.curve_fit states that the independent input may have multiple dimensions.

3
  • Is your independent variables a 1D array? it is hard to see in your snippet. Commented Jul 14, 2014 at 19:23
  • The independent array (Tin_barometer_array) is 2D, it's made from Tin_list and barometer_list: Tin_barometer_array=numpy.array([[Tin_list],[barometer_list]]) Commented Jul 14, 2014 at 20:11
  • Hi, on Stack Overflow we don't put SOLVED in the title. Instead, you can post an answer to your own question and accept it. Commented Jul 15, 2014 at 9:40

2 Answers 2

1

Changing the function definition to:

def func_events_model(xy,a,b,c): return a*xy[0]+b*xy[1]+c 

did the trick.

Sign up to request clarification or add additional context in comments.

Comments

0

If your original intention was to split the two items in xy into separate parameters, you could have done this:

func_events_model(*the_list, a, b, c)

This would have translated into:

func_events_model(the_list[0], the_list[1], a, b, c)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.