python机器学习库numpy---14、numpy实现正态分布
一、总结
一句话总结:
numpy实现正态分布就是 x轴模拟一些点,y轴根据正态分布的公式算出这些点的结果,然后画图即可
# Python实现正态分布
# 绘制正态分布概率密度函数
import numpy as np
import matplotlib.pyplot as plt
u = 0 # 均值μ
sig = np.sqrt(0.2) # 标准差δ
print(sig)
x = np.linspace(u - 3 * sig, u + 3 * sig, 150)
y = np.exp(-(x - u) ** 2 / (2 * sig ** 2)) / (np.sqrt(2 * np.pi) * sig)
print(x)
print("=" * 80)
print(y)
plt.plot(x, y, "r-", linewidth=2)
plt.grid(True)
plt.show()
二、numpy实现正态分布
博客对应课程的视频位置:14、numpy实现正态分布-范仁义-读书编程笔记
https://www.fanrenyi.com/video/38/357
0.4472135954999579
[-1.34164079 -1.32363219 -1.30562358 -1.28761498 -1.26960638 -1.25159778
-1.23358918 -1.21558058 -1.19757198 -1.17956338 -1.16155477 -1.14354617
-1.12553757 -1.10752897 -1.08952037 -1.07151177 -1.05350317 -1.03549457
-1.01748597 -0.99947736 -0.98146876 -0.96346016 -0.94545156 -0.92744296
-0.90943436 -0.89142576 -0.87341716 -0.85540856 -0.83739995 -0.81939135
-0.80138275 -0.78337415 -0.76536555 -0.74735695 -0.72934835 -0.71133975
-0.69333114 -0.67532254 -0.65731394 -0.63930534 -0.62129674 -0.60328814
-0.58527954 -0.56727094 -0.54926234 -0.53125373 -0.51324513 -0.49523653
-0.47722793 -0.45921933 -0.44121073 -0.42320213 -0.40519353 -0.38718492
-0.36917632 -0.35116772 -0.33315912 -0.31515052 -0.29714192 -0.27913332
-0.26112472 -0.24311612 -0.22510751 -0.20709891 -0.18909031 -0.17108171
-0.15307311 -0.13506451 -0.11705591 -0.09904731 -0.08103871 -0.0630301
-0.0450215 -0.0270129 -0.0090043 0.0090043 0.0270129 0.0450215
0.0630301 0.08103871 0.09904731 0.11705591 0.13506451 0.15307311
0.17108171 0.18909031 0.20709891 0.22510751 0.24311612 0.26112472
0.27913332 0.29714192 0.31515052 0.33315912 0.35116772 0.36917632
0.38718492 0.40519353 0.42320213 0.44121073 0.45921933 0.47722793
0.49523653 0.51324513 0.53125373 0.54926234 0.56727094 0.58527954
0.60328814 0.62129674 0.63930534 0.65731394 0.67532254 0.69333114
0.71133975 0.72934835 0.74735695 0.76536555 0.78337415 0.80138275
0.81939135 0.83739995 0.85540856 0.87341716 0.89142576 0.90943436
0.92744296 0.94545156 0.96346016 0.98146876 0.99947736 1.01748597
1.03549457 1.05350317 1.07151177 1.08952037 1.10752897 1.12553757
1.14354617 1.16155477 1.17956338 1.19757198 1.21558058 1.23358918
1.25159778 1.26960638 1.28761498 1.30562358 1.32363219 1.34164079]
================================================================================
[0.00990991 0.01117334 0.01257742 0.01413501 0.01585976 0.01776612
0.01986938 0.02218564 0.02473178 0.02752546 0.03058507 0.03392971
0.03757912 0.04155362 0.04587403 0.05056158 0.05563783 0.06112453
0.06704349 0.07341646 0.08026498 0.08761016 0.09547258 0.10387202
0.11282733 0.12235614 0.13247473 0.1431977 0.15453784 0.16650581
0.17910996 0.19235604 0.20624703 0.22078286 0.23596021 0.2517723
0.26820873 0.28525524 0.30289362 0.32110154 0.33985247 0.35911557
0.37885569 0.39903332 0.41960463 0.44052155 0.46173184 0.48317922
0.50480361 0.52654127 0.54832514 0.57008507 0.59174821 0.61323933
0.6344813 0.65539544 0.67590207 0.69592095 0.7153718 0.73417482
0.75225127 0.76952396 0.78591781 0.80136042 0.81578255 0.82911869
0.84130753 0.85229239 0.86202174 0.87044953 0.8775356 0.88324596
0.88755311 0.8904362 0.89188126 0.89188126 0.8904362 0.88755311
0.88324596 0.8775356 0.87044953 0.86202174 0.85229239 0.84130753
0.82911869 0.81578255 0.80136042 0.78591781 0.76952396 0.75225127
0.73417482 0.7153718 0.69592095 0.67590207 0.65539544 0.6344813
0.61323933 0.59174821 0.57008507 0.54832514 0.52654127 0.50480361
0.48317922 0.46173184 0.44052155 0.41960463 0.39903332 0.37885569
0.35911557 0.33985247 0.32110154 0.30289362 0.28525524 0.26820873
0.2517723 0.23596021 0.22078286 0.20624703 0.19235604 0.17910996
0.16650581 0.15453784 0.1431977 0.13247473 0.12235614 0.11282733
0.10387202 0.09547258 0.08761016 0.08026498 0.07341646 0.06704349
0.06112453 0.05563783 0.05056158 0.04587403 0.04155362 0.03757912
0.03392971 0.03058507 0.02752546 0.02473178 0.02218564 0.01986938
0.01776612 0.01585976 0.01413501 0.01257742 0.01117334 0.00990991]