mean ans std dev of an array?

skip at pobox.com skip at pobox.com
Tue Oct 24 14:43:14 EDT 2006


    >> n = len(a)
    >> mean = sum(a) / n
    >> sd = sqrt(sum((x-mean)**2 for x in a) / n)
    ...
    >> If there is a faster way... like transferring the array to a
    >> different container class...  but what?

Perhaps:

    >>> import scipy
    >>> print scipy.mean([1,2,3,4,5,6])
    3.5
    >>> print scipy.std([1,2,3,4,5,6])
    1.87082869339

Skip



More information about the Python-list mailing list