我無法理解以下代碼有什么問題:import numpy as npimport matplotlib.pyplot as pltfrom scipy.odr import *def gauss(p,x): return p[0]*np.exp(-(x-p[1])**2/(2*p[2]**2)+p[4]) + p[3]# Create a model for fitting.gg = Model(gauss)x = np.arange(0, 350)# Create a RealData object using our initiated data from above.data = RealData(x, y_data, sx=0, sy=y_data_err)# Set up ODR with the model and data.odr = ODR(data, gg, beta0=[0.1, 1., 1.0, 1.0, 1.0])# Run the regression.out = odr.run()# Use the in-built pprint method to give us results.out.pprint()x_fit = np.linspace(x[0], x[-1], 1000)y_fit = gauss(out.beta, x_fit)plt.figure()plt.errorbar(x, xy_data xerr=0, yerr=y_data_err, linestyle='None', marker='x')plt.plot(x_fit, y_fit)plt.show()這是從這里直接復制的,只更改了模型。我得到的錯誤是scipy.odr.odrpack.odr_error: number of observations do not match但據我所知beta0有五個參數,這gauss與工作需要一樣多。如果有人能指出錯誤來源或我的誤解,那就太好了。
考慮不確定性的高斯擬合
慕婉清6462132
2021-08-05 17:59:08