mFlatten {tensorBSS} | R Documentation |
Flattening an Array Along One Mode
Description
Reshapes a higher order array (tensor) into a matrix with a process known as m-mode flattening or matricization.
Usage
mFlatten(x, m)
Arguments
x |
an |
m |
an integer between |
Details
If the original tensor x
has the size p_1 \times \cdots \times p_r \times n
, then mFlatten(x, m)
returns tensor of size p_m \times p_1 \cdots p_{m - 1} p_{m + 1} \cdots p_r \times n
obtained by gathering all m
-mode vectors of x
into a wide matrix (an m
-mode vector of x
is any vector of length p_m
obtained by varying the m
th index and holding the other indices constant).
Value
The m
-mode flattened 3rd order tensor of size p_m \times p_1 \cdots p_{m - 1} p_{m + 1} \cdots p_r \times n
.
Author(s)
Joni Virta
Examples
n <- 10
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)
dim(mFlatten(x, 1))
dim(mFlatten(x, 2))