def stdev(x):
    r"""Calculate standard deviation of data x[]:
        std = sqrt(\sum_i (x_i - mean)^2 \over n-1)
        https://wiki.python.org/moin/NumericAndScientificRecipes
    """
    from math import sqrt
    n = len(x)
    mean = sum(x) / float(n)
    std = sqrt(sum((a - mean)**2 for a in x) / float(n - 1))
    return std