Reshaping a vector into a matrix - represent this as a linear map

367 Views Asked by At

We know that in final dimensional space every linear map can be represented by a matrix. Let $x\in\mathbb{R}^{np \times 1}$ be an $np$-dimensional vector. Then the reshape operation that transforms this vector into a matrix $X\in\mathbb{R}^{n\times p}$ is apparently a linear map.

What is the matrix corresponding to this linear map?

$$ f(x) = \texttt{reshape(}x, \texttt{(n, p))} $$

My Work

I think that one can find the matrix by seeing what happens to each basis. From what I remember, each column of the matrix represents the action of the linear map on the basis vectors.

Hence $$ f(e_1) = \begin{pmatrix} 1 & 0 & \cdots & 0 \\ 0 & 0 & \cdots & 0 \\ \vdots & \vdots & \vdots & \vdots \\ 0 & \cdots & \cdots & 0 \end{pmatrix} $$ and in general one has that $f(e_i)$ has all zeros apart from the entry found at row ((i - 1) % n) + 1 and column (i - 1) ÷ n. I call the matrix with all zeros except with the entry in the $i$ position as above $E_i$. Then $\{E_1, \ldots, E_{np}\}$ is a basis for $\mathbb{R}^{n\times p}$.

Any vector $x\in\mathbb{R}^{np\times 1}$ can be written in terms of the standard basis $\{e_1, \ldots, e_{np}\}$ $$ x = c_1e_1 + \ldots + c_{np} e_{np} $$ for coefficients $c_1, \ldots, c_{np}$. Now this means $$ f(x) = c_1f(e_1) + \ldots + c_{np} f(e_{np}) $$ In turn, each of the vectors $f(e_j)$ can be written in terms of the basis $\{E_1, \ldots, E_{np}\}$ as $$ f(e_j) = a_{1j} E_1 + \ldots + a_{npj} E_{np} $$ Stacking these values into a column gives us the $j^{\text{th}}$ column of the matrix we are looking for. Notice that by definition we have $f(e_j) = E_j$ and so in general $a_{ij} = 0$ unless $i=j$, in which case $a_{ii} = 1$. That is $$ A = \begin{pmatrix} a_{11} & \cdots & a_{1np}\\ \vdots & \vdots & \vdots \\ a_{np1} & \cdots & a_{npnp} \end{pmatrix} = I_{np} $$