,

# Data

This is the value of matrix a

The mean of a’s rows

The stddev of a’s rows

# z-score conversion

z0 function is defined to normalize a vector against its own mean and stddev

z1 function is defined to normalize a vector against another mean and stddev

Applying z0() along the rows of a gives

Applying z0() along the columns of a gives

The result of apply() along the row (axis=1) of the matrix is transposed since each operation return a column vector, and these vectors are cbind to give the final matrix.

Applying z1() with precalculated mean and sd gives