Zufällige Schrittfolge (Random Walk)

Python für Fortgeschrittene

Hugo Bowne-Anderson

Data Scientist at DataCamp

Zufälliger Schritt

Python für Fortgeschrittene

Zufällige Schrittfolge (Random Walk)

In der Wissenschaft bekannt

  • Weg der Moleküle
  • Die finanzielle Lage eines Glücksspielers
Python für Fortgeschrittene

Kopf oder Zahl

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 für Fortgeschrittene

Kopf oder Zahl: Zufällige Schrittfolge (Random Walk)

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 für Fortgeschrittene

Zu gehende Schritte

outcomes
['heads', 'tails', 'heads', 'heads', 'heads', 
 'heads', 'heads', 'tails', 'tails', 'heads']
tails
[0, 0, 1, 1, 1, 1, 1, 1, 2, 3, 3]
Python für Fortgeschrittene

Lass uns üben!

Python für Fortgeschrittene

Preparing Video For Download...