# What is the inverse of the $\mbox{vec}$ operator?

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?

• Are you asking if there is a name for it? Because you certainly can define it. – Git Gud May 22 '14 at 16:20
• The "inverse" of the vectorisation of a matrix is obviously the matrisation of a vector :) – Algebraic Pavel May 22 '14 at 16:22
• One issue to be aware of is that unless $m$ and $n$ are already given, you will not be able to pick a unique matrix such that the given vector is the vectorization of that matrix. For example, the vectorization of $v=[ \begin{matrix} a & b & c & d \end{matrix}]$ is $v^\intercal$, but you wouldn't know if the original matrix was $v, v^\intercal$, or a $2\times 2$ matrix. – Hayden May 22 '14 at 16:24
• However, if $m$ and $n$ are given, then as the wiki article even points out, it is an isomorphism, and thus the inverse clearly exists. – Hayden May 22 '14 at 16:26
• In the context of numerical software, the names are different: In MATLAB, it's reshape, in R, it's matrix, in Mathematica it's Reshape, in Maple it's convert with the matrix option. – Roland May 22 '14 at 16:27

The inverse of the vectorization operator

$$\mbox{vec} : \mathbb{R}^{m \times n} \to \mathbb{R}^{mn}$$

is the operator

$$\mbox{vec}^{-1} : \mathbb{R}^{mn} \to \mathbb{R}^{m \times n}$$

such that

• $\mbox{vec}^{-1} (\mbox{vec} (X)) = X$ for all $X \in \mathbb{R}^{m \times n}$.

• $\mbox{vec} (\mbox{vec}^{-1} (x)) = x$ for all $x \in \mathbb{R}^{m n}$.

Once a matrix is vectorized, the original dimensions of the matrix are "forgotten". Hence, it would be wise to write the dimensions of the inputs of $\mbox{vec}$ and of the outputs of $\mbox{vec}^{-1}$ in subscripts, e.g., $\mbox{vec}_{m,n}$ and $\mbox{vec}_{m,n}^{-1}$. Note that $\mbox{vec}_{3,2}^{-1}$ is the inverse of $\mbox{vec}_{3,2}$, but not of $\mbox{vec}_{2,3}$.

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.$$
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 1, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 22, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.9828310012817383, "perplexity": 171.35391235772246}, "config": {"markdown_headings": true, "markdown_code": false, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2020-50/segments/1606141740670.93/warc/CC-MAIN-20201204162500-20201204192500-00139.warc.gz"}