Python Scipy: Unsupported Operand Type(s) For ** Or Pow(): 'list' And 'list'
I need to fit function to array of data and get optimal coefficients of an equation of this function. I use curve_fit method from scipy library. It is based on least squares method
Solution 1:
It looks like you're after element-wise power-raising?
Like a*x[i]**(b*x[i])
for each i?
In that case, you have to use the np.power
function:
def func(x,a,b):
return a*np.power(x,b*x)
Then it works.
(As an aside, it may be worthwhile to convert x
and y
from lists to numpy arrays: np.array(x)
).
Post a Comment for "Python Scipy: Unsupported Operand Type(s) For ** Or Pow(): 'list' And 'list'"