Náhodná čísla

Intermediate Python

Hugo Bowne-Anderson

Data Scientist at DataCamp

Intermediate Python

Intermediate Python

Intermediate Python

Intermediate Python

Intermediate Python

  • Nelze jít pod schod 0
  • 0,1 % šance pádu ze schodů
  • Sázka: dosáhnete schodů 60
Intermediate Python

Jak to vyřešit?

  • Analyticky
  • Simulovat proces
    • Hackerská statistika!
Intermediate Python

Generátory náhodných čísel

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
Intermediate Python

Generátory náhodných čísel

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

Hod mincí

game.py

import numpy as np

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

Hod mincí

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
Intermediate Python

Pojďme si procvičit!

Intermediate Python

Preparing Video For Download...