Numpy:zero mean data and standardization

econ picture econ · Aug 23, 2017 · Viewed 33.6k times · Source

I saw in tutorial (there were no further explanation) that we can process data to zero mean with x -= np.mean(x, axis=0) and normalize data with x /= np.std(x, axis=0). Can anyone elaborate on these two pieces on code, only thing I got from documentations is that np.mean calculates arithmetic mean calculates mean along specific axis and np.std does so for standard deviation.

Answer

Jonas Adler picture Jonas Adler · Aug 23, 2017

This is also called zscore.

SciPy has a utility for it:

    >>> from scipy import stats
    >>> stats.zscore([ 0.7972,  0.0767,  0.4383,  0.7866,  0.8091,
    ...                0.1954,  0.6307,  0.6599,  0.1065,  0.0508])
    array([ 1.1273, -1.247 , -0.0552,  1.0923,  1.1664, -0.8559,  0.5786,
            0.6748, -1.1488, -1.3324])