Having trouble with scipy.optimize.leastsq
Question: I am new to optimization and having trouble using the least squares
minimization. Here is the code I have tried so far:

def func(tpl, x): return 1./exp(x/360. * tpl)

def errfunc(tpl, x, y): func(tpl,x) - y

//x-axis

xdata = np.array([181,274])

//minimize sum(y - func(x))**2

ydata = np.array([0.992198836646864,0.992996067735572])

//initial guesses

tplInitial1 = (0.031, 0.032) popt, pcov = leastsq(errfunc, tplInitial1[:],
args=(xdata, ydata)) print popt

I was hoping to get [0.032359,0.03071] returned by the minimize function but
getting "only lenght-1 arrays can be converted to Python scalars". Any help is
appreciated. Thank you.


Answer: I suspect you are using `math.exp` instead of `numpy.exp` (i.e. the scalar
version instead of the array version). Try using `from numpy import exp`.

