Skip to content
Snippets Groups Projects
Commit ba98cc02 authored by Marco Biasini's avatar Marco Biasini
Browse files

added Median function

parent c803338f
No related branches found
No related tags found
No related merge requests found
......@@ -47,6 +47,19 @@ def Mean(xs):
raise RuntimeError("Can't calculate mean of empty sequence")
return sum(xs)/len(xs)
@FloatValueExtract
def Median(xs):
"""
Calculate median of dataset
"""
if len(xs)==0:
raise RuntimeError("Can't calculate median of empty sequence")
sorted_xs=sorted(xs)
if (len(xs) % 2)==0:
return (sorted_xs[len(xs)/2]+sorted_xs[len(xs)/2]+1)/2
else:
return sorted_xs[len(xs)/2]
@FloatValueExtract
def StdDev(xs):
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment