0
|
1 #! /usr/bin/python
|
|
2 # stats.py
|
|
3 # P. Clote
|
|
4
|
|
5 import sys,os,tempfile,string,math
|
|
6
|
|
7
|
|
8 def getStats(L):
|
|
9 #L is list
|
|
10 if L==[]:
|
|
11 return (0,0,0,0)
|
|
12 max = -sys.maxint
|
|
13 min = sys.maxint
|
|
14
|
|
15 count = 0
|
|
16 sum = 0.0
|
|
17 sumSquares = 0.0
|
|
18 for value in L:
|
|
19 x = float(value)
|
|
20 if x<min: min=x
|
|
21 if x>max: max=x
|
|
22 count = count+1
|
|
23 sum = sum+x
|
|
24 sumSquares = sumSquares+x**2
|
|
25 mean = sum/count
|
|
26 variance = sumSquares/count - mean**2
|
|
27 stdev = math.sqrt(variance)
|
|
28 #print "Mean:%f\tStDev:%f\tMax:%f\tMin:%f" % (mean,stdev,max,min)
|
|
29 return (mean,stdev,max,min)
|
|
30
|
|
31
|
|
32 if __name__ == '__main__':
|
|
33 L = sys.argv[1:]
|
|
34 (mean,stdev,max,min) = getStats(L)
|
|
35 print "Mean:%f\tStDev:%f\tMax:%f\tMin:%f" % (mean,stdev,max,min)
|
|
36
|