Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from numpy.random import seed #seed is random pattern
- 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
- from numpy import mean #to calculate mean in list/array
- from matplotlib import pyplot #to build histogram
- # Example 1
- means = [mean(randint(1,7,50)) for _ in range(1000)] # calculate mean of (50 random number beetween 1-7) 1000 times
- # print(type(means))
- # print(means)
- pyplot.hist(means)
- pyplot.show()
- pyplot.savefig('1.png')
- # Example 2
- # Make a data distribution
- data = [
- 1,
- 2,2,
- 3,3,3,
- 4,4,4,4,
- 5,5,5,5,5,
- 6,6,6,6,6,6,
- 7,7,7,7,7,7,7,
- 8,8,8,8,8,8,8,8,
- 9,9,9,9,9,9,9,9,9,
- 10,10,10,10,10,10,10,10,10,10
- ]
- val = []
- hisMean = []
- for u in range(500):
- for i in range(1000):
- new = data[randint(0,54)]
- val.append(new)
- rata2 = mean(val)
- hisMean.append(rata2)
- val = []
- # print(type(hisMean))
- # print(hisMean)
- pyplot.hist(hisMean)
- pyplot.show()
- pyplot.savefig('2.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement