net.py: typo fix + catch the right exception
[breadcrumb.git] / code / breadcrumb / analysis / tools.py
blobcbe11e33d22a92a556fd1eb57ddb4e5b556400c2
1 import math
3 def standard_deviation(seq, mu):
4 """Returns the standard deviation of a given sequence."""
5 for x in seq:
6 s_sq = s_sq + (x - mu)**2
7 s_cm = s_cm + (x - mu)
9 var = (s_sq - (s_cm**2)/len(seq))/(len(seq) - 1)
10 return math.sqrt(var)
12 def z_scores(seq, mu, sigma):
13 """
14 Returns an list of Z-scores (standard deviations from the mean).
16 Given a sequence of floats, a mean value (mu) and a standard deviation
17 (sigma), this returns a list of equal length as the input sequence.
19 The input sequence must be 1D.
20 """
21 return [float((value - mu)/sigma) for value in seq]