Skip to content

Instantly share code, notes, and snippets.

@kimbo
Created October 25, 2018 22:17
Show Gist options
  • Save kimbo/53b54d97f9e8acf3440293fdbca004cf to your computer and use it in GitHub Desktop.
Save kimbo/53b54d97f9e8acf3440293fdbca004cf to your computer and use it in GitHub Desktop.
Standard deviation functions
from math import sqrt
test_data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
pstd_dev = lambda data: sqrt(sum([((sum(data) / len(data)) - x)**2 for x in data]) / len(data))
std_dev = lambda data: sqrt(sum([((sum(data) / len(data)) - x)**2 for x in data]) / (len(data) - 1))
print(pstd_dev(test_data))
print(std_dev(test_data))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment