forked from UW-Madison-ACI/simplestats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
stats.py
36 lines (32 loc) · 862 Bytes
/
stats.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
def mean(vals):
"""Computes the mean from a list of values.
Let's get this right!"""
try:
total = float(sum(vals))
length = len(vals)
except TypeError:
raise TypeError("The list was not numbers.")
except:
print "Something unknown happened with the list."
return total/length
def median(vals):
"""please implement this function"""
pass
def mode(vals):
"""Computes the mode from a list of values."""
pass
def std(vals):
"""Computes the standard deviation from a list of values."""
n = len(vals)
if n == 0:
return 0.0
mu = sum(vals) / n
if mu == 1e500:
return NotImplemented
var = 0.0
for val in vals:
var = var + (val - mu)**2
return (var / n)**0.5
def var(vals):
"""Computes the variance from a list of values."""
pass