This repository has been archived by the owner on Aug 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnormal-distribution.py
56 lines (45 loc) · 1.56 KB
/
normal-distribution.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
## Normal Distribution
## python -m pip install matplotlib
import random
import matplotlib.pyplot as plt
# Distribution: It shows how the values are distributed
# Normal Distribution: A distribution in which values close to the mean are more commonly distributed than values further from the mean
# Histogram: Show frequency distribution of values.
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Standard Normal Distribution -> variance = 1 and mean = 0
samples = []
for i in range(100000):
samples.append(random.normalvariate(mu=0, sigma=1))
# samples.append(random.paretovariate(alpha=1))
# print(samples)
plt.hist(samples, bins=200)
plt.show()
# Proving and showing how many times each number is repeated
distro = [0, 0, 0, 0, 0, 0, 0]
for x in samples:
x = int(abs(x) // 1)
distro[x] += 1
for i,x in enumerate(distro):
print(f"Numbers close to {i} have been repeated {x} times")
print(distro)
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
samples = []
for i in range(100000):
samples.append(random.choice([100, 200, 300]))
# print(samples)
plt.hist(samples, bins=10)
plt.show()
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
samples = []
for i in range(100000):
samples.append(random.choice([100, 200, 300, 300]))
# print(samples)
plt.hist(samples, bins=10)
plt.show()
###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
samples = []
for i in range(100000):
samples.append(random.choice([50, 50, 50, 100, 200, 300, 300]))
# print(samples)
plt.hist(samples, bins=10)
plt.show()