Skip to content

Commit 7566e23

Browse files
committed
update day27 homework
1 parent 2cfd23e commit 7566e23

File tree

1 file changed

+15
-18
lines changed

1 file changed

+15
-18
lines changed

D27_Discrete/homework.py

+15-18
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,23 @@
66
import math
77
import statistics
88

9+
# 離散均勻分配( Discrete Uniform Distribution )
10+
# 伯努利分配( Bernoulli Distribution )
11+
# 二項分配(Binomial Distribution)
12+
# 今天我們透過作業中的問題,回想今天的內容吧!
13+
# 丟一個銅板,丟了100次,出現正面 50 次的機率有多大。
14+
915
'''
10-
# 離散均勻分配 (Discrete Uniform Distribution)
11-
# 前提:其中有限個數值擁有相同的機率。
16+
你的答案
1217
'''
13-
# 1.定義離散均勻分配的基本資訊
18+
# 這是 bermoulli分配
19+
p = 0.5 # 假設是公平硬幣
20+
n = 100 # 重複實驗 100次,
21+
r = 50 # 計算出現50次正面
22+
1423

15-
low=1
16-
high=7
17-
r = np.arange(low,high)
18-
# 2.計算離散均勻分配的概率質量分佈 (probability mass function)
24+
# 2.計算二項分佈的概率質量分佈 (probability mass function)
1925
# 之所以稱為質量,是因為離散的點
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)
2426
# 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()
27+
probs = stats.binom.pmf(r, n, p)
28+
print(probs)

0 commit comments

Comments
 (0)