rowNorms | R Documentation |
Efficiently compute the norms of all row or column vectors of a dense or sparse matrix.
rowNorms(M, method = "euclidean", p = 2) colNorms(M, method = "euclidean", p = 2)
M |
a dense or sparse numeric matrix |
method |
norm to be computed (see “Norms” below for details) |
p |
exponent of the Values 0 ≤ p < 1 are also permitted as an extension but do not correspond to a proper mathematical norm (see details below). |
A numeric vector containing one norm value for each row or column of M
.
Given a row or column vector x, the following length measures can be computed:
euclidean
The Euclidean norm given by
|x|_2 = sqrt( SUM(i) (x_i)^2 )
maximum
The maximum norm given by
|x|_Inf = MAX(i) |x_i|
manhattan
The Manhattan norm given by
|x|_1 = SUM(i) |x_i|
minkowski
The Minkowski (or L_p) norm given by
|x|_p = [ SUM(i) |x_i|^p ]^(1/p)
for p ≥ 1. The Euclidean (p = 2) and Manhattan (p = 1) norms are special cases, and the maximum norm corresponds to the limit for p -> Inf.
As an extension, values in the range 0 ≤ p < 1 are also allowed and compute the length measure
|x|_p = SUM(i) |x_i|^p
For 0 < p < 1 this formula defines a p-norm, which has the property |r * x| = |r|^p * |x| for any scalar factor r instead of being homogeneous. For p = 0, it computes the Hamming length, i.e. the number of nonzero elements in the vector x.
Stephanie Evert (https://purl.org/stephanie.evert)
dist.matrix
, normalize.rows
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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.