| rowNorms {wordspace} | R Documentation |
Compute Norms of Row and Column Vectors of a Matrix (wordspace)
Description
Efficiently compute the norms of all row or column vectors of a dense or sparse matrix.
Usage
rowNorms(M, method = "euclidean", p = 2)
colNorms(M, method = "euclidean", p = 2)
Arguments
M |
a dense or sparse numeric matrix |
method |
norm to be computed (see “Norms” below for details) |
p |
exponent of the Values |
Value
A numeric vector containing one norm value for each row or column of M.
Norms
Given a row or column vector x, the following length measures can be computed:
euclideanThe Euclidean norm given by
\|x\|_2 = \sqrt{ \sum_i x_i^2 }maximumThe maximum norm given by
\|x\|_{\infty} = \max_i |x_i|manhattanThe Manhattan norm given by
\|x\|_1 = \sum_i |x_i|minkowskiThe Minkowski (or
L_p) norm given by\|x\|_p = \left( \sum_i |x_i|^p \right)^{1/p}for
p \ge 1. The Euclidean (p = 2) and Manhattan (p = 1) norms are special cases, and the maximum norm corresponds to the limit forp \to \infty.As an extension, values in the range
0 \le p < 1are also allowed and compute the length measure\|x\|_p = \sum_i |x_i|^pFor
0 < p < 1this formula defines ap-norm, which has the property\|r\cdot x\| = |r|^p \cdot \|x\|for any scalar factorrinstead of being homogeneous. Forp = 0, it computes the Hamming length, i.e. the number of nonzero elements in the vectorx.
Author(s)
Stephanie Evert (https://purl.org/stephanie.evert)
See Also
Examples
rowNorms(DSM_TermContextMatrix, "manhattan")
# fast and memory-friendly nonzero counts with "Hamming length"
rowNorms(DSM_TermContextMatrix, "minkowski", p=0)
colNorms(DSM_TermContextMatrix, "minkowski", p=0)
sum(colNorms(DSM_TermContextMatrix, "minkowski", p=0)) # = nnzero(DSM_TermContextMatrix)