KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I've done a search and the problem seems similar to Python scipy: unsupported operand type(s) for ** or pow(): 'list' and 'list' however the solution posted there did not work and I think it may actually be different. I am trying to fit a curve to data using scipy.curve_fit, when I leave all 3 parameters free everything works correctly and I get the expected result. def func(x,a,b,c): return a*np.exp(b*(x**c)) popt, pcov = curve_fit(func,x,y) However when I try to fix one of the values (c=2) as below, def func2(x,a,b): return a*np.exp(b*(x**2)) popt, pcov = curve_fit(func2,x,y) I get TypeError: unsupported operand type(s) for ** or pow(): 'int' and 'list' using numpy.power(x,2) as suggested in the linked question allows the code to run but produces the wrong result. Anyone see what I'm doing wrong? Edited to add: Even more confusingly leastsq, which as far I know is used by curve_fit, with the 2nd formula works. 2nd Edit: To those to mentioned the list problems X and Y are now both arrays and the code runs without error. However func2 still produces drastically the wrong result. (I would post the graph here but apparently I need more rep.) Func 1 curvefit gives [a,b,c] = [ 1.71890826, -0.0239123, 3.17039851] however for func2 it all goes wrong [a,b] = [ -2.88694423e-15, 9.99999998e-01] . I don't understand how such a small change can be causing such a drastic problem, leastsq was able to fit this data with c=2.
Tags (comma-separated)
Save Edits
Cancel