パラメータとして振幅のみを使用して、正弦+余弦曲線をデータに適合させようとしていますが、パラメータが1つしかない関数ではcurve_fitが機能しないようです...
import numpy as np
import scipy.optimize as scio
def function(x,a):
y = a*np.sin(np.radians(x))
return y
x = np.array(range(360))
y = function(x,3)
yn = y +0.2 * np.random.normal(size=len(x))
popt,pcov = scio.curve_fit(function,x,yn)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/Users/mj/Documents/NACO/VLT/DataReduction/<ipython-input-62-388a2d20a0c8> in <module>()
----> 1 popt,pcov = scio.curve_fit(function,x,yn)
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/optimize/minpack.pyc in curve_fit(f, xdata, ydata, p0, sigma, **kw)
416
417 if (len(ydata) > len(p0)) and pcov is not None:
--> 418 s_sq = (func(popt, *args)**2).sum()/(len(ydata)-len(p0))
419 pcov = pcov * s_sq
420 else:
/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/scipy/optimize/minpack.pyc in _general_function(params, xdata, ydata, function)
319
320 def _general_function(params, xdata, ydata, function):
--> 321 return function(xdata, *params) - ydata
322
323 def _weighted_general_function(params, xdata, ydata, function, weights):
TypeError: function() argument after * must be a sequence, not numpy.float64
これはなぜcurve_fitの問題なのですか? 私は何か間違ったことをしていますか?
前もって感謝します!MJO