pkern_mat2vec | R Documentation |
Maps matrix indices i, j to a single vectorized index, k
pkern_mat2vec(ij, gdim, simplified = TRUE)
ij |
n x 2 matrix, the row and column indices |
gdim |
integer (or vector with first element equal to) the number of rows in the matrix |
simplified, |
if FALSE, the function returns an n x 1 matrix |
Column vectorization (as in base::as.vector
) builds a length(mn) vector by stacking
the columns of an m X n matrix, with the leftmost column appearing first in the vector
and the rightmost column last. Matrix element i,j gets mapped to element k = i + m * (j-1)
in the vector. This function returns that index.
ij
can be a matrix or a list of length-n vectors 'i' and 'j', or a vector
representing a single point at the given row (i) and column (j) number (in that order).
gdim
should either be an integer number of rows in the matrix, or a vector of the form
c(ni, nj)
(the return value of dim
for example) in which case its first element is used.
integer vector, the vectorized ij
indices
# define matrix dimensions and look up a specific index
gdim = c(4, 5)
ij = c(i=3, j=2)
pkern_mat2vec(ij, gdim)
# display all matrix indices in column-vectorized order
gyx = expand.grid(i=seq(gdim[1]), j=seq(gdim[2]))
result = pkern_mat2vec(gyx, gdim)
data.frame(k=result, gyx)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.