Description Usage Arguments Details Value Author(s) Examples
View source: R/tensorVectorize.R
Vectorizes an array of array-valued observations into a matrix so that each column of the matrix corresponds to a single observational unit.
1 |
x |
Array of an order at least two with the last dimension corresponding to the sampling units. |
Vectorizes a p_1 x p_2 x ... x p_r x n-dimensional array into a p_1 p_2 ... p_r x n-dimensional matrix, each column of which then corresponds to a single observational unit. The vectorization is done so that the rth index goes through its cycle the fastest and the first index the slowest.
Note that the output is a matrix of the size "number of variables" x "number of observations", that is, a transpose of the standard format for a data matrix.
Matrix whose columns contain the vectorized observed tensors.
Joni Virta
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # Generate sample data.
n <- 100
x <- t(cbind(rnorm(n, mean = 0),
rnorm(n, mean = 1),
rnorm(n, mean = 2),
rnorm(n, mean = 3),
rnorm(n, mean = 4),
rnorm(n, mean = 5)))
dim(x) <- c(3, 2, n)
# Matrix of vectorized observations.
vecx <- tensorVectorize(x)
# The covariance matrix of individual tensor elements
cov(t(vecx))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.