We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 41a7ded commit 2cfd23eCopy full SHA for 2cfd23e
D27_Discrete/homework.py
@@ -0,0 +1,31 @@
1
+# library
2
+import matplotlib.pyplot as plt
3
+import numpy as np
4
+import pandas as pd
5
+from scipy import stats
6
+import math
7
+import statistics
8
+
9
+'''
10
+# 離散均勻分配 (Discrete Uniform Distribution)
11
+# 前提:其中有限個數值擁有相同的機率。
12
13
+# 1.定義離散均勻分配的基本資訊
14
15
+low=1
16
+high=7
17
+r = np.arange(low,high)
18
+# 2.計算離散均勻分配的概率質量分佈 (probability mass function)
19
+# 之所以稱為質量,是因為離散的點
20
+# 產生 x 軸的點
21
+#r = np.arange(stats.randint.ppf(0.01, low, high),
22
+# stats.randint.ppf(0.99, low, high),1)
23
+print(r)
24
+# P(X=x) --> 是機率
25
+probs = stats.randint.pmf(r,low,high)
26
+print(probs)
27
+plt.bar(r, probs)
28
+plt.ylabel('P(X=x)')
29
+plt.xlabel('x')
30
+plt.title('pmf of DU(1,6)')
31
+plt.show()
0 commit comments