TITLE: What is the inverse of the $\mbox{vec}$ operator?
QUESTION [13 upvotes]: There is a well known vectorization operator $\mbox{vec}$ in matrix analysis. 
I've vectorized my matrix equations, did some transformation of vectorized  equations and now I want to get back to the matrix form. Is there special operator for it?

REPLY [17 votes]: Adding to the excellent answer by Rodrigo de Azevedo, I would like to point out that there is an explicit formula for the inverse $\operatorname{vec}_{m\times n}^{-1}$, given by
$$
\mathbb{R}^{mn}\ni x \mapsto \operatorname{vec}_{m\times n}^{-1}(x) = \big((\operatorname{vec} I_n)^\top \otimes I_m\big)(I_n \otimes x) \in \mathbb{R}^{m\times n},
$$
where $I_n$ denotes the $n\times n$ identity matrix and $\otimes$ denotes the Kronecker product.

The formula above can be verified in the following way:
Let $X\in\mathbb{R}^{m\times n}$ be such that $\operatorname{vec}{X}=x\in\mathbb{R}^{mn}$, and let $X_k$ denote the $k$-th column of $X$. Additionally, let $M=I_n\otimes x \in\mathbb{R}^{mn^2\times n}$ and let $M_k$ denote the $k$-th column of $M$. Finally, we let $e_k\in\mathbb{R}^n$ be the $k$-th column of $I_n$. Note that $M_k=e_k\otimes\operatorname{vec}{X}$.
Recall the identity $\operatorname{vec}(ABC) = (C^\top\otimes A)\operatorname{vec}{B}$, which we shall make heavy use of.
Observing that $\operatorname{vec}(e_k^\top\otimes X)=M_k$, we see that
$$
\big((\operatorname{vec} I_n)^\top \otimes I_m\big)M_k =
\big((\operatorname{vec} I_n)^\top \otimes I_m\big)\operatorname{vec}(e_k^\top\otimes X) =
\operatorname{vec}\big(I_m(e_k^\top\otimes X)\operatorname{vec}{I_n}\big) =
\operatorname{vec}\big((e_k^\top\otimes X)\operatorname{vec}{I_n}\big) =
\operatorname{vec}\big(\operatorname{vec}(XI_ne_k)\big) =
\operatorname{vec}(Xe_k) = X_k,
$$
and thus
$$
\big((\operatorname{vec} I_n)^\top \otimes I_m\big)M =
\big((\operatorname{vec} I_n)^\top \otimes I_m\big)
\begin{bmatrix} M_1 & \ldots & M_n \end{bmatrix} =
\begin{bmatrix} X_1 & \ldots & X_n \end{bmatrix} = X.
$$