统计分布(均匀、高斯|正态)

http://t.csdnimg.cn/XDUM3

均匀分布python代码

import numpy as np  
import matplotlib.pyplot as plt  
  
# 设定参数  
a = 2       # (a-b)均匀分布下限  
b = 3       # (a-b)均匀分布上限  
fs = 1e7    # 采样率,单位:Hz  
t = 1e-3    # 随机序列长度,单位:s  
n = int(t * fs)  # 采样点数  
  
# 生成(0, 1)单位均匀分布的随机数  
np.random.seed(0)  # 设置随机数生成器的种子  
u = np.random.rand(n)  
  
# 由(0,1)分布转换到(a, b)均匀分布  
x = (b - a) * u + a  
  
# 绘制信号图  
plt.figure(figsize=(10, 6))  
plt.subplot(211)  
plt.plot(x)  
plt.title('均匀分布信号')  
plt.xlabel('样本')  
plt.ylabel('幅度')  
  
# 绘制直方图  
plt.subplot(212)  
plt.hist(x, bins=np.arange(a, b+0.01, 0.01), alpha=0.7, edgecolor='black')  
plt.title('均匀分布信号直方图')  
plt.xlabel('幅度')  
plt.ylabel('频率')  
  
plt.tight_layout()  
plt.show()

高斯分布(正态分布)

概念:正态分布、标准正态分布(定义、期望、方差、例题)
https://zhuanlan.zhihu.com/p/503557666

正态分布python代码

import numpy as np  
import matplotlib.pyplot as plt  
  
# 定义x的范围,从-10到10,步长为0.01  
x = np.arange(-10, 10, 0.01)  
  
# 计算正态分布的概率密度函数,均值为0,标准差为1  
y = np.exp(-x**2 / 2) / np.sqrt(2 * np.pi)  
  
# 创建图形和坐标轴  
plt.figure(figsize=(8, 6))  
ax = plt.axes([0.1, 0.1, 0.85, 0.85])  
  
# 绘制正态分布曲线  
plt.plot(x, y)  
  
# 设置y轴和x轴的显示范围  
plt.ylim([-0.01, 0.43])  
plt.xlim([-3, 3])  
  
# 显示图形  
plt.show()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值