normalize.rows {wordspace} | R Documentation |
Normalize Rows or Columns of Matrix to Unit Length (wordspace)
Description
Efficiently normalize the row or column vectors of a dense or sparse matrix to unit length.
Usage
normalize.rows(M, method = "euclidean", p = 2, ...,
tol = 1e-6, inplace = FALSE)
normalize.cols(M, method = "euclidean", p = 2, ...,
tol = 1e-6, inplace = FALSE)
Arguments
M |
a dense or sparse numeric matrix |
method |
norm to be computed, see |
p |
exponent of Minkowski p-norm in the range |
... |
|
tol |
row/column vectors with norm below |
inplace |
if |
Details
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.
Value
A row-normalized (or column-normalized) matrix with the same dimensions as M
.
Author(s)
Stephanie Evert (https://purl.org/stephanie.evert)
See Also
See rowNorms
for details on available norms and their parameters.