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 , the following length measures can be computed:
euclidean
The Euclidean norm given by
maximum
The maximum norm given by
manhattan
The Manhattan norm given by
minkowski
The Minkowski (or
) norm given by
for
. The Euclidean (
) and Manhattan (
) norms are special cases, and the maximum norm corresponds to the limit for
.
As an extension, values in the range
are also allowed and compute the length measure
For
this formula defines a
-norm, which has the property
for any scalar factor
instead of being homogeneous. For
, it computes the Hamming length, i.e. the number of nonzero elements in the vector
.
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)