gpt4 book ai didi

python - Python 中函数的数学积分

转载 作者:太空宇宙 更新时间:2023-11-03 12:42:24 24 4
gpt4 key购买 nike

我正在尝试集成此功能:

enter image description here

但是我遇到了一个错误:

Traceback (most recent call last):

File "<ipython console>", line 1, in <module>

File "siestats.py", line 349, in NormalDistro

P_inner = scipy.integrate(NDfx,-dev,dev)

TypeError: 'module' object is not callable

我的代码运行这个:

# Definition of the mathematical function:
def NDfx(x):

return((1/math.sqrt((2*math.pi)))*(math.e**((-.5)*(x**2))))

# This Function normailizes x, u, and o2 (position of interest, mean and st dev)
# and then calculates the probability up to position 'x'

def NormalDistro(u,o2,x):


dev = abs((x-u)/o2)


P_inner = scipy.integrate(NDfx,-dev,dev)

P_outer = 1 - P_inner

P = P_inner + P_outer/2

return(P)

函数 NormalDistro 用于导入并像这样使用:

foo.NormalDistro(30,2.5,1.25)

举个例子。

最佳答案

您尝试调用的模块是scipy.integrate,您需要调用模块中的函数之一。基于之前对 chat 的评论您可能想使用 scipy.integrate.quad()

此外,它返回一个 (Result,MaximumError) 的元组,因此您不应在 P 的求和中直接使用 P_inner ,你想要 P = P_inner[0] + P_outer/2

关于python - Python 中函数的数学积分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5046845/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com