Guest User

Untitled

a guest
Mar 20th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. #Random Walk
  2. import random
  3. import numpy as np
  4. import matplotlib.pyplot as plt
  5.  
  6. walks = []
  7. for walk in range(200):
  8. position = 0
  9. for step in range(30):
  10. if random.random() > 0.4:
  11. position += 1
  12. else:
  13. position -= 1
  14. walks.append(position)
  15.  
  16. plt.hist(walks, bins = 20)
  17. plt.show()
  18. #variance
  19. print (np.var(walks))
  20. #mean
  21. print (np.mean(walks))
Add Comment
Please, Sign In to add comment