Normalization rows or columns of a matrix
normalize( X, dim = 1, weights = if (dim == 1) 1/sqrt(rowSums(X^2)) else 1/sqrt(colSums(X^2)) )
X
: matrix with numeric valuesdim
: which dimension to normalize (1 for rows, 2 for columns)weights
: vector with normalization weights, by default 2-norm is used