Verteilung

Python für Fortgeschrittene

Hugo Bowne-Anderson

Data Scientist at DataCamp

Verteilung

Python für Fortgeschrittene

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

100 Durchläufe

distribution.py

import numpy as np
np.random.seed(123)
final_tails = []

for x in range(100) : tails = [0] for x in range(10) : coin = np.random.randint(0, 2) tails.append(tails[x] + coin)
final_tails.append(tails[-1])
print(final_tails)
[3, 6, 4, 5, 4, 5, 3, 5, 4, 6, 6, 8, 6, 4, 7, 5, 7, 4, 3, 3, ..., 4]
Python für Fortgeschrittene

Histogramm, 100 Durchläufe

distribution.py

import numpy as np

import matplotlib.pyplot as plt
np.random.seed(123) final_tails = [] for x in range(100) : tails = [0] for x in range(10) : coin = np.random.randint(0, 2) tails.append(tails[x] + coin) final_tails.append(tails[-1])
plt.hist(final_tails, bins = 10) plt.show()
Python für Fortgeschrittene

Histogramm, 100 Durchläufe

Python für Fortgeschrittene

Histogramm, 1.000 Durchläufe

distribution.py

import numpy as np
import matplotlib.pyplot as plt

np.random.seed(123) final_tails = [] for x in range(1000) : # <-- tails = [0] for x in range(10) : coin = np.random.randint(0, 2) tails.append(tails[x] + coin) final_tails.append(tails[-1])
plt.hist(final_tails, bins = 10) plt.show()
Python für Fortgeschrittene

Histogramm, 1.000 Durchläufe

Python für Fortgeschrittene

Histogramm, 10.000 Durchläufe

distribution.py

import numpy as np
import matplotlib.pyplot as plt

np.random.seed(123) final_tails = [] for x in range(10000) : # <-- tails = [0] for x in range(10) : coin = np.random.randint(0, 2) tails.append(tails[x] + coin) final_tails.append(tails[-1])
plt.hist(final_tails, bins = 10) plt.show()
Python für Fortgeschrittene

Histogramm, 10.000 Durchläufe

Python für Fortgeschrittene

Lass uns üben!

Python für Fortgeschrittene

Preparing Video For Download...