Rastgele Yürüyüş

Orta Seviye Python

Hugo Bowne-Anderson

Data Scientist at DataCamp

Rastgele Adım

Orta Seviye Python

Rastgele Yürüyüş

Bilimde bilinir

  • Moleküllerin yolu
  • Kumarbazın mali durumu
Orta Seviye Python

Tura mı Yazı mı

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']
Orta Seviye Python

Tura mı Yazı mı: Rastgele Yürüyüş

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]
Orta Seviye Python

Yürüyüşe Adım

outcomes
['heads', 'tails', 'heads', 'heads', 'heads', 
 'heads', 'heads', 'tails', 'tails', 'heads']
tails
[0, 0, 1, 1, 1, 1, 1, 1, 2, 3, 3]
Orta Seviye Python

Hadi pratik yapalım!

Orta Seviye Python

Preparing Video For Download...