# $CVSHeader: pal8e/src/Sigma.py,v 1.3 2005/02/15 01:10:26 indraneel Rel $

# calculates standard deviation of data

import math

class Sigma(list):
    def __sigma(self, mean):
        def difference_square(x):
            return ((x-mean)*(x-mean))
        S = map(difference_square, self)
        variance = sum(S)/(len(self)-1)
        standard_deviation = math.sqrt(variance)
        return standard_deviation

    def sigma(self, mean=None):
        if (mean == None):
            mean = sum(self)/len(self)
        return self.__sigma(mean)
