Created
October 14, 2019 19:13
-
-
Save claclacla/814ff4e435ed47e6e9568e1fbbe2e749 to your computer and use it in GitHub Desktop.
The standard deviation calculated using python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Standard deviation formula: | |
# SD = sqrt(sum(x - m)**2) / n | |
# x: the value in the dataset | |
# m: the mean of the dataset | |
# n: the number of values in the dataset | |
import math | |
N = [32, 30, 29, 33] | |
# Find the mean of the values | |
m = 0 | |
for n in N: | |
m += n | |
m /= len(N) | |
# Find the sum of the distance of each value to the mean | |
s = 0 | |
for n in N: | |
s += (n - m)**2 | |
# Divide by the number of values | |
s /= len(N) | |
# Finally... take the square! | |
r = math.sqrt(s) | |
print(r) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment