scipy.stats.norm函数

在这里插入代码片

scipy.stats.norm函数 可以实现正态分布(也就是高斯分布)

pdf : 概率密度函数
标准形式是:
在这里插入图片描述
norm.pdf(x, loc, scale)
等同于
norm.pdf(y) / scale ,其中 y = (x - loc) / scale

调用方式用两种,见代码

import numpy as np
from scipy.stats import norm
import matplotlib.pyplot as plt
from matplotlib import style
style.use('fivethirtyeight')

fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111)
np.random.seed(0)

X = np.linspace(-5, 5, num=20)

# 第一种调用方式
gauss = norm(loc=1, scale=2)  # loc: mean 均值, scale: standard deviation 标准差
r_1 = gauss.pdf(X)

# 第二种调用方式
r_2 = norm.pdf(X, loc=0, scale=2)

for i in range(len(X)):
    ax.scatter(X[i], 0, s=100)
for g, c in zip([r_1, r_2], ['r', 'g']):  # 'r': red, 'g':green
    ax.plot(X, g, c=c)

plt.show()

在这里插入图片描述

参考:
scipy.stats.norm()

猜你喜欢

转载自blog.csdn.net/m0_37586991/article/details/89792673