-
Notifications
You must be signed in to change notification settings - Fork 0
/
MathsFunda.py
32 lines (24 loc) · 841 Bytes
/
MathsFunda.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
import numpy as np
import math
# Ref: https://www.mathsisfun.com/data/standard-deviation.html
def standard_deviation():
"""
SQRT of variance is the standard deviation!
:return:
"""
# Example: Input: height of dogs
# Outout : Standard Deviation
dog_heights_mm = [600, 470, 170, 430, 300]
np_dog_heights_mm = np.array(dog_heights_mm)
# Forst calculate Mean
mean = np_dog_heights_mm.mean()
print('Mean of dog height:', mean)
variance = 0;
for height in np_dog_heights_mm :
# Square each difference
variance = variance + (height - mean)**2
variance_mean = variance / len(np_dog_heights_mm)
print('Variance Mean value:', variance_mean)
standard_deviation = math.sqrt(variance_mean)
print('Standard Deviation:', standard_deviation)
standard_deviation()