Phân phối

Python nâng cao

Hugo Bowne-Anderson

Data Scientist at DataCamp

Phân phối

Python nâng cao

Bước ngẫu nhiên

headtailsrw.py

import numpy as np
np.random.seed(123)
tails = [0]
for x in range(10) :
    coin = np.random.randint(0, 2)
    tails.append(tails[x] + coin)
Python nâng cao

100 lần chạy

distribution.py

import numpy as np
np.random.seed(123)
final_tails = []

for x in range(100) : tails = [0] for x in range(10) : coin = np.random.randint(0, 2) tails.append(tails[x] + coin)
final_tails.append(tails[-1])
print(final_tails)
[3, 6, 4, 5, 4, 5, 3, 5, 4, 6, 6, 8, 6, 4, 7, 5, 7, 4, 3, 3, ..., 4]
Python nâng cao

Biểu đồ tần suất, 100 lần chạy

distribution.py

import numpy as np

import matplotlib.pyplot as plt
np.random.seed(123) final_tails = [] for x in range(100) : tails = [0] for x in range(10) : coin = np.random.randint(0, 2) tails.append(tails[x] + coin) final_tails.append(tails[-1])
plt.hist(final_tails, bins = 10) plt.show()
Python nâng cao

Biểu đồ tần suất, 100 lần chạy

Python nâng cao

Biểu đồ tần suất, 1.000 lần chạy

distribution.py

import numpy as np
import matplotlib.pyplot as plt

np.random.seed(123) final_tails = [] for x in range(1000) : # <-- tails = [0] for x in range(10) : coin = np.random.randint(0, 2) tails.append(tails[x] + coin) final_tails.append(tails[-1])
plt.hist(final_tails, bins = 10) plt.show()
Python nâng cao

Biểu đồ tần suất, 1.000 lần chạy

Python nâng cao

Biểu đồ tần suất, 10.000 lần chạy

distribution.py

import numpy as np
import matplotlib.pyplot as plt

np.random.seed(123) final_tails = [] for x in range(10000) : # <-- tails = [0] for x in range(10) : coin = np.random.randint(0, 2) tails.append(tails[x] + coin) final_tails.append(tails[-1])
plt.hist(final_tails, bins = 10) plt.show()
Python nâng cao

Biểu đồ tần suất, 10.000 lần chạy

Python nâng cao

Ayo berlatih!

Python nâng cao

Preparing Video For Download...