I have the following data set
angles =np.arange(-90,91,15)
n_col_cnts =([ 0.08692008,0.46557143,0.7282595,0.89681908,0.97057961,1.,0.99488705,0.91823478,0.84187586, 0.73110934,0.53363229,0.25338418,0.01328528])
I would like to fit a gaussian to this data using optimize.leastsq()
from scipy
but have reached a stumbling block. Here is what I have attempted from here
fitfunc = lambda p, x: p[0]*math.exp(-((x-p[1])/p[2])**2) #Target function
errfunc = lambda p, x, y: fitfunc(p, x) - y # Distance to the target function
p0 = [1., 0., 30.] # Initial guess for the parameters
fit, success = optimize.leastsq(errfunc, p0[:], args=(angles,n_col_cnts))
However I get the error message
TypeError: only length-1 arrays can be converted to Python scalars
which I do not understand. What have I done wrong?