我一直收到相同的错误消息,不知道为什么。
def function_to_fit(x, a, b):
return (a*x) + b
fit_guess = np.array([ 2., 0.])
popt, pcov = curve_fit(function_to_fit, x, y, sigma=y_err, p0=fit_guess)
print("Fit Parameters:", popt)
print("Fit Parameter Uncertainties:", np.sqrt(np.diag(pcov)))
# calculate chi^2 and reduced chi^2
chi2 = np.sum(((y-function_to_fit(x, *popt))/y_err)**2)
print("chi^2:", chi2)
print("Reduced chi^2:", chi2/(len(x) - len(fit_guess)))
TypeError: can't multiply sequence by non-int of type 'numpy.float64'