I have a numpy matrix containing numbers.
1,0,1,1
0,1,1,1
0,0,1,0
1,1,1,1
I would like to perform a Z-Score Normalization over each column; z_Score[y] = (y-mean(column))/sqrt(var) y being each element in the column, mean being the mean function, sqrt the squared root function and var the variance.
My Approach was the following:
x_trainT = x_train.T #transpose the matrix to iterate over columns
for item in x_trainT:
m = item.mean()
var = np.sqrt(item.var())
item = (item - m)/var
x_train = x_trainT.T
I thought that upon iteration, each row is accessed by reference, (like in c# lists for instance), therefore allowing me to change the matrix values through changing row values.
However I was wrong, since the matrix keeps its original values intact.
Your help is appreciated.