[SciPy-dev] scipy.stats.zs

Tim Leslie tim.leslie at gmail.com
Thu Jun 29 22:53:42 EDT 2006


The function scipy.stats.zs, which calculates the z-score of each
element of an array, currently recalculates the mean and samplestd for
each element, which leads to an O(n^2) running time.  Writing the
function as follows fixes this and brings it back to O(n) running
time.

def zs (a):
"""
Returns a 1D array of z-scores, one for each score in the passed array,
computed relative to the passed array.

"""
    mu = mean(a, None)
    sigma = samplestd(a)
    return array([(score - mu)/sigma for score in a])

I'm having a few issues with both svn and trac right now, so I can't
provide a patch or lodge a ticket, but I'll try to do something about
that when I get on to a less broken machine later tonight if noone's
picked this up by then.

Cheers,

Tim Leslie



More information about the SciPy-Dev mailing list