Skip to content

Commit 2cfd23e

Browse files
committedMar 4, 2021
upload day27 homework
1 parent 41a7ded commit 2cfd23e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
 

‎D27_Discrete/homework.py

+31
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)
Please sign in to comment.