How to do curvefitting using scipy.optimize.curve_fit
<p>I am quite new to Python. I wanted to do a sum of exponentials fit to my data using curve_fit. Here's my code:</p>

<pre><code>import numpy as np
from scipy.optimize import curve_fit

xdata= np.array('1, 8, 8, 21, 31, 42, 63, 64, 81, 110, 156, 211, 301, 336, 735')
ydata = np.array('0.018, 0.0164, 0.0042, 0.0072, 0.0108, 0.0044, 0.0035, 0.0036, 0.0042, 0.0051, 0.0019, 0.0042, 0.0019, 8e-4, 2e-4')

def func(x,a,b,m,n):
    return a*np.exp(m*x)+b*np.exp(n*x)

curve_fit(func, xdata, ydata)
</code></pre>

<p>I get the typeerror stating: "ufunc 'multiply' did not contain a loop with signature matching types dtype('

<p>Can somebody please help me with this? Also, I would like to set a constraint such that parameters a and b add to 1.</p>

<p>Thank you.</p>

<pre><code>import numpy as np
from scipy.optimize import curve_fit

xdata= np.array([1, 8, 8, 21, 31, 42, 63, 64, 81, 110, 156, 211, 301, 336, 735])
ydata = np.array([0.018, 0.0164, 0.0042, 0.0072, 0.0108, 0.0044, 0.0035, 0.0036, 0.0042, 0.0051, 0.0019, 0.0042, 0.0019, 8e-4, 2e-4])

def func(x,a,b,m,n):
    return a*np.exp(m*x)+b*np.exp(n*x)

curve_fit(func, xdata, ydata)
</code></pre>

<p>unfortunatly <code>Covariance of the parameters could not be estimated</code></p>

python optimization scipy