Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. from numpy.random import seed #seed is random pattern
  2. from numpy.random import randint #randint(a,b,c), a is smallest value, b is biggest values, c is how much the random number is generated in list/array
  3. from numpy import mean #to calculate mean in list/array
  4. from matplotlib import pyplot #to build histogram
  5.  
  6. # Example 1
  7. means = [mean(randint(1,7,50)) for _ in range(1000)] # calculate mean of (50 random number beetween 1-7) 1000 times
  8. # print(type(means))
  9. # print(means)
  10. pyplot.hist(means)
  11. pyplot.show()
  12. pyplot.savefig('1.png')
  13.  
  14. # Example 2
  15. # Make a data distribution
  16. data = [
  17.     1,
  18.     2,2,
  19.     3,3,3,
  20.     4,4,4,4,
  21.     5,5,5,5,5,
  22.     6,6,6,6,6,6,
  23.     7,7,7,7,7,7,7,
  24.     8,8,8,8,8,8,8,8,
  25.     9,9,9,9,9,9,9,9,9,
  26.     10,10,10,10,10,10,10,10,10,10
  27. ]
  28. val = []
  29. hisMean = []
  30.  
  31. for u in range(500):
  32.     for i in range(1000):
  33.         new = data[randint(0,54)]
  34.         val.append(new)
  35.     rata2 = mean(val)
  36.     hisMean.append(rata2)
  37.     val = []
  38.  
  39. # print(type(hisMean))
  40. # print(hisMean)
  41. pyplot.hist(hisMean)
  42. pyplot.show()
  43. pyplot.savefig('2.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement