Created
May 13, 2012 01:20
-
-
Save jrovegno/2670108 to your computer and use it in GitHub Desktop.
standard deviation of the values
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
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