我正在使用 python 2.7 和名为“不确定性”的模块来分析实验数据。我有两个数组,polycoeffs 和 cov,它们是由 numpy 函数 polyfit 生成的。我已经设法从 cov 数组中提取了前导对角线,并且我试图将这些值与名为 uncert_coeffs 的列表中的适当系数与不确定性函数“ufloat”进行匹配。这是代码:
polycoeffs,cov=polyfit(wav,trans,6,cov=True) #wav and trans are themselves, arrays.
print "Polycoeffs= ",polycoeffs
print "Cov= ",cov
cov_diag=[]
for element in diag(cov):
cov_diag.append(str(element))
print "The diagonal of the covariant matrix= ",cov_diag
ord_counter=6
uncert_coeffs=[]
cov_index=0
for i in polycoeffs:
uncert=(cov_diag[cov_index])
print "uncert: ",uncert
temp=ufloat("(i+/-uncert)") #error here
uncert_coeffs.append(temp)
cov_index+=1
print "The polynomial coefficients with uncertainties, are: ",uncert_coeffs
这会产生错误:
ValueError: Cannot parse (i+/-uncert): was expecting a number like 1.23+/-0.1
所以我的问题是:在这种情况下,手动组合 polycoeff 和它们的不确定性将是一种非常痛苦的情况,我怎样才能让 ufloat 解包变量 uncert?此外,uncert 的值大多是科学计数法。