Skip to content

Instantly share code, notes, and snippets.

@claclacla
Created October 14, 2019 19:13
Show Gist options
  • Save claclacla/814ff4e435ed47e6e9568e1fbbe2e749 to your computer and use it in GitHub Desktop.
Save claclacla/814ff4e435ed47e6e9568e1fbbe2e749 to your computer and use it in GitHub Desktop.
The standard deviation calculated using python
# 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