In multilinear algebra, a reshaping of tensors is any bijection between the set of indices of an order-
tensor and the set of indices of an order-
tensor, where
. The use of indices presupposes tensors in coordinate representation with respect to a basis. The coordinate representation of a tensor can be regarded as a multi-dimensional array, and a bijection from one set of indices to another therefore amounts to a rearrangement of the array elements into an array of a different shape. Such a rearrangement constitutes a particular kind of linear map between the vector space of order-
tensors and the vector space of order-
tensors.
Definition[edit]
Given a positive integer
, the notation
refers to the set
of the first M positive integers.
For each integer
where
for a positive integer
, let
denote an
-dimensional vector space over a field
. Then there are vector space isomorphisms (linear maps)
![{\displaystyle {\begin{aligned}V_{1}\otimes \cdots \otimes V_{M}&\simeq F^{I_{1}}\otimes \cdots \otimes F^{I_{M}}\\&\simeq F^{I_{\pi _{1}}}\otimes \cdots \otimes F^{I_{\pi _{M}}}\\&\simeq F^{I_{\pi _{1}}I_{\pi _{2}}}\otimes F^{I_{\pi _{3}}}\otimes \cdots \otimes F^{I_{\pi _{M}}}\\&\simeq F^{I_{\pi _{1}}I_{\pi _{3}}}\otimes F^{I_{\pi _{2}}}\otimes F^{I_{\pi _{4}}}\otimes \cdots \otimes F^{I_{\pi _{M}}}\\&\,\,\,\vdots \\&\simeq F^{I_{1}I_{2}\ldots I_{M}},\end{aligned}}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/7d8d28e903fbeb49d2a870e0045f50bc611b869a)
where
is any permutation and
is the symmetric group on
elements. Via these (and other) vector space isomorphisms, a tensor can be interpreted in several ways as an order-
tensor where
.
Coordinate representation[edit]
The first vector space isomorphism on the list above,
, gives the coordinate representation of an abstract tensor. Assume that each of the
vector spaces
has a basis
. The expression of a tensor with respect to this basis has the form
![{\displaystyle {\mathcal {A}}=\sum _{i_{1}=1}^{I_{1}}\ldots \sum _{i_{M}=1}^{I_{M}}a_{i_{1},i_{2},\ldots ,i_{M}}v_{i_{1}}^{1}\otimes v_{i_{2}}^{2}\otimes \cdots \otimes v_{i_{M}}^{M},}](https://wikimedia.org/api/rest_v1/media/math/render/svg/5c46f4527b133d56d24578d9c1cd64557a76df10)
where the coefficients
![{\displaystyle a_{i_{1},i_{2},\ldots ,i_{M}}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/c9d2b2f1e4cc13d3898f60744e38ea641a3ef3a0)
are elements of
![{\displaystyle F}](https://wikimedia.org/api/rest_v1/media/math/render/svg/545fd099af8541605f7ee55f08225526be88ce57)
. The coordinate representation of
![{\displaystyle {\mathcal {A}}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/280ae03440942ab348c2ca9b8db6b56ffa9618f8)
is
![{\displaystyle \sum _{i_{1}=1}^{I_{1}}\ldots \sum _{i_{M}=1}^{I_{M}}a_{i_{1},i_{2},\ldots ,i_{M}}\mathbf {e} _{i_{1}}^{1}\otimes \mathbf {e} _{i_{2}}^{2}\otimes \cdots \otimes \mathbf {e} _{i_{M}}^{M},}](https://wikimedia.org/api/rest_v1/media/math/render/svg/2295a78076676823d0c34e16430da0279d1973fa)
where
![{\displaystyle \mathbf {e} _{i}^{m}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/6bccefcc1053fe1c6abf7cdac4931cbda2e26992)
is the
standard basis vector of
![{\displaystyle F^{I_{m}}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/3e639324deab6b8e0bb001b15a8c1821bbc39492)
. This can be regarded as a
M-way array whose elements are the coefficients
![{\displaystyle a_{i_{1},i_{2},\ldots ,i_{M}}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/c9d2b2f1e4cc13d3898f60744e38ea641a3ef3a0)
.
General flattenings[edit]
For any permutation
there is a canonical isomorphism between the two tensor products of vector spaces
and
. Parentheses are usually omitted from such products due to the natural isomorphism between
and
, but may, of course, be reintroduced to emphasize a particular grouping of factors. In the grouping,
![{\displaystyle (V_{\pi (1)}\otimes \cdots \otimes V_{\pi (r_{1})})\otimes (V_{\pi (r_{1}+1)}\otimes \cdots \otimes V_{\pi (r_{2})})\otimes \cdots \otimes (V_{\pi (r_{L-1}+1)}\otimes \cdots \otimes V_{\pi (r_{L})}),}](https://wikimedia.org/api/rest_v1/media/math/render/svg/e6e253aaa9502517bf59f85ddd023b0cb4df7895)
there are
![{\displaystyle L}](https://wikimedia.org/api/rest_v1/media/math/render/svg/103168b86f781fe6e9a4a87b8ea1cebe0ad4ede8)
groups with
![{\displaystyle r_{l}-r_{l-1}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/31172ff68b0cd3c8fee117a4a2fd353725d68e60)
factors in the
![{\displaystyle l^{\text{th}}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/3b52d0e1ba21e8828aceed29fe5c441505391ab7)
group (where
![{\displaystyle r_{0}=0}](https://wikimedia.org/api/rest_v1/media/math/render/svg/59ae7aa89f5f67919e9d115efafb0216047e6d62)
and
![{\displaystyle r_{L}=M}](https://wikimedia.org/api/rest_v1/media/math/render/svg/f2f7c60ac480ef4e60368b42738af93a627ff97a)
).
Letting
for each
satisfying
, an
-flattening of a tensor
, denoted
, is obtained by applying the two processes above within each of the
groups of factors. That is, the coordinate representation of the
group of factors is obtained using the isomorphism
, which requires specifying bases for all of the vector spaces
. The result is then vectorized using a bijection
to obtain an element of
, where
, the product of the dimensions of the vector spaces in the
group of factors. The result of applying these isomorphisms within each group of factors is an element of
, which is a tensor of order
.
Vectorization[edit]
By means of a bijective map
, a vector space isomorphism between
and
is constructed via the mapping
where for every natural number
such that
, the vector
denotes the ith standard basis vector of
. In such a reshaping, the tensor is simply interpreted as a vector in
. This is known as vectorization, and is analogous to vectorization of matrices. A standard choice of bijection
is such that
![{\displaystyle \operatorname {vec} ({\mathcal {A}})={\begin{bmatrix}a_{1,1,\ldots ,1}&a_{2,1,\ldots ,1}&\cdots &a_{n_{1},1,\ldots ,1}&a_{1,2,1,\ldots ,1}&\cdots &a_{I_{1},I_{2},\ldots ,I_{M}}\end{bmatrix}}^{T},}](https://wikimedia.org/api/rest_v1/media/math/render/svg/cd105e9e9da72d7764fd6464c38cd52a46f7159e)
which is consistent with the way in which the colon operator in Matlab and GNU Octave reshapes a higher-order tensor into a vector. In general, the vectorization of
is the vector
.
The vectorization of
denoted with
or
is an
-reshaping where
and
.
Mode-m Flattening / Mode-m Matrixization[edit]
Let
be the coordinate representation of an abstract tensor with respect to a basis. Mode-m matrixizing (a.k.a. flattening) of
is an
-reshaping in which
and
. Usually, a standard matrixizing is denoted by
![{\displaystyle {\mathbf {A} }_{[m]}={\mathcal {A}}_{[S_{1},S_{2}]}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/5348d48b787eb9e1e8fca0bacf1359ab5113b9df)
This reshaping is sometimes called matrixizing, matricizing, flattening or unfolding in the literature. A standard choice for the bijections
is the one that is consistent with the reshape function in Matlab and GNU Octave, namely
![{\displaystyle {\mathbf {A} }_{[m]}:={\begin{bmatrix}a_{1,1,\ldots ,1,1,1,\ldots ,1}&a_{2,1,\ldots ,1,1,1,\ldots ,1}&\cdots &a_{I_{1},I_{2},\ldots ,I_{m-1},1,I_{m+1},\ldots ,I_{M}}\\a_{1,1,\ldots ,1,2,1,\ldots ,1}&a_{2,1,\ldots ,1,2,1,\ldots ,1}&\cdots &a_{I_{1},I_{2},\ldots ,I_{m-1},2,I_{m+1},\ldots ,I_{M}}\\\vdots &\vdots &&\vdots \\a_{1,1,\ldots ,1,I_{m},1,\ldots ,1}&a_{2,1,\ldots ,1,I_{m},1,\ldots ,1}&\cdots &a_{I_{1},I_{2},\ldots ,I_{m-1},I_{m},I_{m+1},\ldots ,I_{M}}\end{bmatrix}}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/e1231e2f5eed3aa2b17d8553b7785f9f6a7c863c)
Definition Mode-m Matrixizing:[1]
![{\displaystyle [{\mathbf {A} }_{[m]}]_{jk}=a_{i_{1}\dots i_{m}\dots i_{M}},\;\;{\text{ where }}j=i_{m}{\text{ and }}k=1+\sum _{n=0 \atop n\neq m}^{M}(i_{n}-1)\prod _{l=0 \atop l\neq m}^{n-1}I_{l}.}](https://wikimedia.org/api/rest_v1/media/math/render/svg/ed2f6b47cbf1e55ad6b59fc2469c28de1fb09701)
The mode-
m matrixizing of a tensor
![{\displaystyle {\mathcal {A}}\in F^{I_{1}\times ...I_{M}},}](https://wikimedia.org/api/rest_v1/media/math/render/svg/8c16d0083bd4aca7c0555d0b6768dd6f93775acd)
is defined as the matrix
![{\displaystyle {\mathbf {A} }_{[m]}\in F^{I_{m}\times (I_{1}\dots I_{m-1}I_{m+1}\dots I_{M})}}](https://wikimedia.org/api/rest_v1/media/math/render/svg/d78104d10c5567d7da3a1a01e4f65a398f854e46)
. As the parenthetical ordering indicates, the mode-
m column vectors are arranged by sweeping all the other mode indices through their ranges, with smaller mode indexes varying more rapidly than larger ones; thus
References[edit]