我试图在其他函数“ totalUncertainty”中调用函数“ statisticalUncertainty”。但是,当我执行statisticalUncertainty的输出时,将返回一个数字和“ none”,这给了我一个错误。当我在totalUncertainty中使用它时,为什么返回“ none”,而当我单独使用它时却不返回?
我尝试不定义typeAUnc,而只是将statisticalUncertainty(xdata)直接放入totalUnc的定义中,但这仍然会得到相同的错误。
import numpy as np
xdata1=[72.2,77.6,82.4,86.3,88.9]
xdata2=[80.10,81.45,81.50,81.34,82.01]
def statisticalUncertainty(xdata):
n = len(xdata)
meanXdata=np.mean(xdata)
for i in range(1,n):
innerSum=0
innerSum=innerSum+(xdata[i]-meanXdata)**2
std = np.sqrt(innerSum*(1/(n*(n-1))))
print(std)
def totalUncertainty(xdata,typeBUnc):
typeAUnc = statisticalUncertainty(xdata)
totalUnc = 2*(np.sqrt((typeAUnc)**2)+((typeBUnc)**2))
print(totalUnc)
totalUncertainty(xdata1,0.5)
我得到的错误是:
TypeError: unsupported operand type(s) for ** or pow(): 'NoneType' and 'int'