目录

Python Normal Distribution

正态分布是通过在数据中排列每个值的概率分布来呈现数据的形式。大多数值保持在平均值附近,使得排列对称。

我们在numpy库中使用各种函数来数学计算正态分布的值。 创建直方图,我们在其上绘制概率分布曲线。

import matplotlib.pyplot as plt
import numpy as np
mu, sigma = 0.5, 0.1
s = np.random.normal(mu, sigma, 1000)
# Create the bins and histogram
count, bins, ignored = plt.hist(s, 20, normed=True)
# Plot the distribution curve
plt.plot(bins, 1/(sigma * np.sqrt(2 * np.pi)) *
    np.exp( - (bins - mu)**2/(2 * sigma**2) ),       linewidth=3, color='y')
plt.show()

output如下 -

normdist.png
↑回到顶部↑
WIKI教程 @2018