做数据的时候经常会用到均匀分布和正态分布,通过画图来详细看一下区别。
# !/usr/bin/env python
# -*-coding:utf-8 -*-
"""
# Time :2022/5/16 1:39
# Desc :uniform and normal distribution test.
"""
import numpy as np
import matplotlib.pyplot as plt
if __name__ == '__main__':
L = 10000
indices = np.linspace(0, L, L)
uni_dist = np.random.uniform(-5, 20, L)
nor_dist = np.random.normal(loc=5, scale=10, size=L)
plt.hist(nor_dist, bins=100, color="blue", label="normal")
plt.hist(uni_dist, bins=100, color="red", label="uniform")
plt.grid()
plt.legend()
plt.xlabel("snr")
plt.ylabel("prob")
plt.show()结论: 正态分布范围会更广,在均值处对称集中; 均匀分布只在限定范围内,范围小,均匀分布;
|