분포

중급 Python

Hugo Bowne-Anderson

Data Scientist at DataCamp

분포

중급 Python

랜덤 워크

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

100회 실행

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

100회 실행 시의 히스토그램

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

100회 실행 시의 히스토그램

중급 Python

1,000회 실행 시의 히스토그램

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

1,000회 실행 시의 히스토그램

중급 Python

10,000회 실행 시의 히스토그램

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

10,000회 실행 시의 히스토그램

중급 Python

연습해 봅시다!

중급 Python

Preparing Video For Download...