import pylab as plb
import matplotlib.pyplot as plt
from scipy.optimize import curve_fit
from scipy import asarray as ar,exp
import numpy as np
x = time
y = sick
#gaussian: f(x) = a * e^(-0.5 * ((x-μ)/σ)**2)
n = len(str(a))
mean = sum(x*y)/n
sigma = sum(y*(x-mean)**2)/n
def gaus(x,a,x0,sigma):
return a*exp(-(x-x0)**2/(2*sigma**2))
popt, pcov = curve_fit(gaus, x, y, p0 = [1, mean, sigma])
plt.plot(x,y,label='Data Observasi')
plt.plot(x,gaus(x,*popt),label='Kurva Fit')
plt.title('Gaussian')
plt.xlabel('X')
plt.ylabel('Y')
plt.show()
为什么当我运行配置时出现错误 “类型错误:根据规则“安全”,无法将数组数据从dtype('O')转换为dtype('float64')”
请提供错误帮助,以便我可以运行配置
谢谢