python - 总值(value)错误的分布图

标签 python numpy distribution normal-distribution

创建enter image description here 我用下面的代码制作了分布图:

from numpy import *
import numpy as np
import matplotlib.pyplot as plt

sigma = 4.1

x = np.linspace(-6*sigma, 6*sigma, 200)

def distr(n):
    def g(x):
        return (1/(sigma*sqrt(2*pi)))*exp(-0.5*(x/sigma)**2)
    FxSum = 0
    a = list()
    for i in range(n):
        # divide into 200 parts and sum one by one
        numb = g(-6*sigma + (12*sigma*i)/n)
        FxSum += numb
        a.append(FxSum)
    return a

plt.plot(x, distr(len(x)))
plt.show()

enter image description here

当然,这是一种无需使用 hist()、cdf() 或 Python 库中的任何其他选项即可获取结果的方法。

为什么总和不是1?它不应该依赖于(例如)西格玛。

最佳答案

几乎正确,但为了积分,您必须将函数值 g(x) 乘以微小间隔 dx (12*sigma/200 )。这就是您总结的区域:

from numpy import *
import numpy as np
import matplotlib.pyplot as plt

sigma = 4.1

x = np.linspace(-6*sigma, 6*sigma, 200)

def distr(n):
    def g(x):
        return (1/(sigma*sqrt(2*pi)))*exp(-0.5*(x/sigma)**2)
    FxSum = 0
    a = list()
    for i in range(n):
        # divide into 200 parts and sum one by one
        numb = g(-6*sigma + (12*sigma*i)/n) * (12*sigma/200)
        FxSum += numb
        a.append(FxSum)
    return a

plt.plot(x, distr(len(x)))
plt.show()

关于python - 总值(value)错误的分布图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58751405/

相关文章:

python json 类型错误 : string indices must be integers

Python 快速 DataFrame 连接

python - 在Windows上使用pip安装Scipy python包时出错

python - 用我的项目创建 Python pip 包

python - 如何提示 Sympy 逆高斯方程的积分

用于探测 smtp 服务器的 Python 脚本

python - 罗莎琳德 "Mendel' s 第一定律“IPRB

具有固定长度但顺序填充新值的 Python 数组

python - pyinstaller numpy "Intel MKL FATAL ERROR: Cannot load mkl_intel_thread.dll"

statistics - 衡量两个分布之间的差异