난수

중급 Python

Hugo Bowne-Anderson

Data Scientist at DataCamp

중급 Python

중급 Python

중급 Python

중급 Python

중급 Python

  • 0번째 계단 아래로 내려갈 수 없음
  • 계단에서 넘어질 확률 0.1%
  • 내기: 60번째 계단까지 도달 가능?
중급 Python

해결 방법은?

  • 분석적:
  • 과정을 시뮬레이션
    • 해커 통계!
중급 Python

난수 생성기

import numpy as np
np.random.rand()      # Pseudo-random numbers
0.9535543896720104    # Mathematical formula
np.random.seed(123)    # Starting from a seed
np.random.rand()
0.6964691855978616
np.random.rand()
0.28613933495037946
중급 Python

난수 생성기

np.random.seed(123)
np.random.rand()
0.696469185597861    # Same seed: same random numbers!
np.random.rand()     # Ensures "reproducibility"
0.28613933495037946
중급 Python

동전 던지기

game.py

import numpy as np

np.random.seed(123)
coin = np.random.randint(0,2) # Randomly generate 0 or 1
print(coin)
0
중급 Python

동전 던지기

game.py

import numpy as np
np.random.seed(123)
coin = np.random.randint(0,2)  # Randomly generate 0 or 1
print(coin)

if coin == 0: print("heads")
else: print("tails")
0
heads
중급 Python

연습해 봅시다!

중급 Python

Preparing Video For Download...