Skip to content

Instantly share code, notes, and snippets.

@jrovegno
Created May 13, 2012 01:20
Show Gist options
  • Save jrovegno/2670108 to your computer and use it in GitHub Desktop.
Save jrovegno/2670108 to your computer and use it in GitHub Desktop.
standard deviation of the values
import numpy as np
def std2(x):
sum, sum2, n = 0.0, 0.0, 0.0
for k in x:
sum += k
sum2 += k*k
n += 1
return sum2/n - sum*sum/(n*n)
a = [1,2,3,4,5,6,7,8,9]
## Ref http://docs.scipy.org/doc/numpy/reference/generated/numpy.std.html
print np.std(a)**2 - std2(a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment