Skip to content

Instantly share code, notes, and snippets.

@waffle2k
Created February 12, 2014 14:01
Show Gist options
  • Save waffle2k/8956064 to your computer and use it in GitHub Desktop.
Save waffle2k/8956064 to your computer and use it in GitHub Desktop.
Calculate the mean deviation
#!/usr/bin/python
import sys
numerator_set = []
for input in sys.stdin.readlines():
numerator_set.append( float(input) )
numerator = sum( numerator_set ) * 1.0
mean = numerator / len( numerator_set )
distance_set = map( lambda x: abs( x - mean ), numerator_set )
mean_deviation = sum( distance_set ) / len( distance_set )
numerator_set.sort()
print "sum : %.2f" % ( numerator )
print "count : %.2f" % ( len(numerator_set) )
print "max : %.2f" % ( numerator_set[-1] )
print "min : %.2f" % ( numerator_set[0] )
print "mean : %.2f" % ( mean )
print "mean deviation : %.2f" % ( mean_deviation )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment