Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Random Walk
- import random
- import numpy as np
- import matplotlib.pyplot as plt
- walks = []
- for walk in range(200):
- position = 0
- for step in range(30):
- if random.random() > 0.4:
- position += 1
- else:
- position -= 1
- walks.append(position)
- plt.hist(walks, bins = 20)
- plt.show()
- #variance
- print (np.var(walks))
- #mean
- print (np.mean(walks))
Add Comment
Please, Sign In to add comment