01.正太分布模型

import numpy as np
import matplotlib.pyplot as plt 
from math import sqrt, pi, exp


def normal_distribution(mu, sigma):
    # 调用函数生成一组正态分布随机数
    size = 100000
    noise = np.random.normal(mu, sigma, size)
    # 正态分布的概率密度函数
    x = np.linspace(mu - 3 * sigma, mu + 3 * sigma, 50)
    y = np.exp(-(x - mu) ** 2 / (2 * sigma ** 2)) / (sigma * sqrt(2 * pi))

    plt.hist(noise, bins=100, density=True)
    plt.plot(x, y)
    plt.show()


if __name__ == "__main__":
    normal_distribution(25, 5)

原文地址:https://www.cnblogs.com/waterr/p/13947965.html