랜덤 워크

중급 Python

Hugo Bowne-Anderson

Data Scientist at DataCamp

무작위 단계

중급 Python

랜덤 워크

과학에서 알려진 개념

  • 분자의 이동 경로
  • 도박꾼의 재정 상태
중급 Python

앞면 또는 뒷면

headtails.py

import numpy as np
np.random.seed(123)
outcomes = []
for x in range(10) :
    coin = np.random.randint(0, 2)
    if coin == 0 :
        outcomes.append("heads")
    else :
        outcomes.append("tails")

print(outcomes)
['heads', 'tails', 'heads', 'heads', 'heads', 
 'heads', 'heads', 'tails', 'tails', 'heads']
중급 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)
print(tails)
[0, 0, 1, 1, 1, 1, 1, 1, 2, 3, 3]
중급 Python

무작위 단계에서 랜덤 워크로

outcomes
['heads', 'tails', 'heads', 'heads', 'heads', 
 'heads', 'heads', 'tails', 'tails', 'heads']
tails
[0, 0, 1, 1, 1, 1, 1, 1, 2, 3, 3]
중급 Python

연습해 봅시다!

중급 Python

Preparing Video For Download...