Marche aléatoire

Python intermédiaire

Hugo Bowne-Anderson

Data Scientist at DataCamp

Pas aléatoire

Python intermédiaire

Marche aléatoire

Reconnu dans le domaine scientifique

  • Trajectoire des molécules
  • Situation financière du joueur
Python intermédiaire

Pile ou face

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 intermédiaire

Pile ou face : Marche aléatoire

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 intermédiaire

Des pas pour une marche

outcomes
['heads', 'tails', 'heads', 'heads', 'heads', 
 'heads', 'heads', 'tails', 'tails', 'heads']
tails
[0, 0, 1, 1, 1, 1, 1, 1, 2, 3, 3]
Python intermédiaire

Passons à la pratique !

Python intermédiaire

Preparing Video For Download...