Mercurial > repos > xuebing > sharplabtool
diff tools/mytools/stats.txt @ 0:9071e359b9a3
Uploaded
author | xuebing |
---|---|
date | Fri, 09 Mar 2012 19:37:19 -0500 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tools/mytools/stats.txt Fri Mar 09 19:37:19 2012 -0500 @@ -0,0 +1,36 @@ +#! /usr/bin/python +# stats.py +# P. Clote + +import sys,os,tempfile,string,math + + +def getStats(L): + #L is list + if L==[]: + return (0,0,0,0) + max = -sys.maxint + min = sys.maxint + + count = 0 + sum = 0.0 + sumSquares = 0.0 + for value in L: + x = float(value) + if x<min: min=x + if x>max: max=x + count = count+1 + sum = sum+x + sumSquares = sumSquares+x**2 + mean = sum/count + variance = sumSquares/count - mean**2 + stdev = math.sqrt(variance) + #print "Mean:%f\tStDev:%f\tMax:%f\tMin:%f" % (mean,stdev,max,min) + return (mean,stdev,max,min) + + +if __name__ == '__main__': + L = sys.argv[1:] + (mean,stdev,max,min) = getStats(L) + print "Mean:%f\tStDev:%f\tMax:%f\tMin:%f" % (mean,stdev,max,min) +