relation between indices of a tensor and its vectorization

429 Views Asked by At

Assume three-mode tensor $A \in R^{n_1 \times n_2 \times n_3}$ and its vectorization as $a=vec(A)$. What is the relation between the index elements of tensor $A$ and vector $a$? Specifically, I would like to know which element of tensor $A$ is correspond to the $i$th element of vector $a$.

2

There are 2 best solutions below

4
On

I'll assume that you're following this convention of vectorization. I also assume that your indexing starts at one, which (unfortunately perhaps) is a bit more common in mathematical literature on tensors.

The $(i,j,k)$ entry of the tensor $A$ is mapped to the $p$th vector entry, with $$ p = 1 + (i-1) + n_1(j-1) + n_1n_2(k-1). $$ Going in the opposite direction, we find that the $p$th vector entry corresponds to the $(i,j,k)$ element of the tensor $A$, with $$ i = 1 + ([p-1] \bmod n_1), \\ j = 1 + ([p - i - 1] \bmod n_1n_2) = 1 + \lfloor[p - n_1n_2(k-1) - 1]/n_1\rfloor, \\ k = 1 + \lfloor (p-1)/(n_1n_2)\rfloor. $$ As the two forms of $j$ indicate, there are two general ways to compute these indices (for tensors of arbitrary order). You can either compute these indices from left to right using the modulo operator or from right to left using integer division.

0
On

More generally, for a tensor $A \in \mathbb{R}^{r_1 \times \cdots \times r_m} $, an entry $a_{i_1, \cdots, i_m}$ of $A$ maps to the $j$-th entry of vec$(A)$, in which $j=1+\sum_{k=1}^m(i_k-1)\prod_{k'=1}^{k-1}r_{k'}$. You can understand this vectorization as stacking the model-1 fibers of $A$.