normalize.rows | R Documentation |
Efficiently normalize the row or column vectors of a dense or sparse matrix to unit length.
normalize.rows(M, method = "euclidean", p = 2, ..., tol = 1e-6, inplace = FALSE) normalize.cols(M, method = "euclidean", p = 2, ..., tol = 1e-6, inplace = FALSE)
M |
a dense or sparse numeric matrix |
method |
norm to be computed, see |
p |
exponent of Minkowski p-norm in the range 0 < p ≤ ∞. Note that normalization is not possible for very small values of p. |
... |
any further arguments are passed to |
tol |
row/column vectors with norm below |
inplace |
if |
These functions return a matrix with row (or column) vectors rescaled to a length of 1 according to the selected norm.
All-zero vectors (with |0| = 0) cannot be normalized. In order to avoid scaling up rounding errors, rows (or columns) with |x| < tol are explicitly set to 0 (and thus not normalized). Since a suitable threshold for rounding errors depends on the scaling behaviour of the selected norm and the provenance of M, it is advisable to set tol
explicitly to an appropriate value. Pass tol = 0
to normalize all nonzero vectors.
The generalized Minkowski norm with p < 1 is not homogeneous but can still be normalized. This is numerically unstable for very small values of p, which will be rejected with an error message. The Hamming length (p = 0) cannot be normalized at all. See rowNorms
for more information.
A row-normalized (or column-normalized) matrix with the same dimensions as M.
Stephanie Evert (https://purl.org/stephanie.evert)
See rowNorms
for details on available norms and their parameters.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.