[Math] Correct notation for writing array reshape

matricesmatrix equationsnotationvectors

Suppose I am coding in python.

Then one can do e.g. something like this:

import numpy as np
A = np.random.rand((6,6))
# Lets reshape it
A_new = A.reshape(-1,3)

So it went from 2D array (matrix) to a 2D array with six 12 rows and three columns.

How would one write the re-shape operation formally in mathematical notation? Transpose is obviously easy, but is there a parallel for reshapes?

$$\mathbf{A} \in \mathbb{R}^{6\times6} \rightarrow \mathbf{A} \in \mathbb{R}^{12 \times 3}$$

Thx

Best Answer

The operation $\mathbb{R}^{n\times m}\to\mathbb{R}^{nm}$ is called vectorization and often is denoted with $\mathop{\mathrm{vec}}()$. Creating a matrix from vector is an inverse $\mathop{\mathrm{vec}^{-1}}()$. When one can't deduce what are the dimensions of new matrix, they can be given as sub-indices: $\mathop{\mathrm{vec}^{-1}_{3,4}}(\mathbf v)$ will produce the matrix $3\times 4$. To sum up, you can write: $$ \mathop{\mathrm{vec}^{-1}_{12,3}}\circ\mathop{\mathrm{vec}}: \mathbb{R}^{6\times 6}\to\mathbb{R}^{12,3},\\ A'= \mathop{\mathrm{vec}^{-1}_{12,3}}(\mathop{\mathrm{vec}}(A)). $$

However, I need to mention, that it isn't a widely used notation, so you are better to introduce it formally beforehand.

Note. There is also a term tensor reshaping, but it's usually referred to an operation of combining dimensions (so no dimension is needed to be a composite integer).