# Vectorization of a diagonal matrix

Is there any representation for the vectorization of a diagonal matrix $$\text{vec}(\text{Diag}(x))$$?

For example, for two elements $$\text{vec}(\begin{bmatrix} x_1 & 0 \\ 0 &x_2 \end{bmatrix}) = \begin{bmatrix} 1 & 0 \\ 0 & 0 \\ 0 & 0 \\ 0 & 1 \end{bmatrix} \begin{pmatrix} x_1 \\ x_2 \end{pmatrix} \ .$$

In general case, $$\text{vec}(\text{Diag}(x)) = A x$$, what is the closed form for matrix $$A$$?

• What do you mean by "closed form"? Is "the matrix whose $\left(i,j\right)$-th entry is $1$ if $j-1 = \left(n+1\right)\left(i-1\right)$ and $0$ otherwise" a closed form? Because that's what $A$ is. – darij grinberg Sep 22 '19 at 6:28
• @darijgrinberg it seems there is a typo in your condition. Should be $i-1 = (n+1)(j-1)$ as in two elements example 1 in the $(4,2)$ entry. However, I am looking for $A$ to be some linear function. For example, $A = \sum_i e_i e_i^T \otimes e_i$, where $e_i$ is the i-th standard basis vector. – Andrey Gorbunov Sep 22 '19 at 8:12
• Oops, you are right about $i$ and $j$ being swapped. – darij grinberg Sep 22 '19 at 8:23

$$A : \Bbb R^n \to \Bbb R^{n^2}$$. Let $$e_i, i = 1, ..., n$$ be the canonical basis vectors of $$\Bbb R^n$$, and let $$f_j, j = 1, ..., n^2$$ be the canonical basis vectors of $$\Bbb R^{n^2}$$
Then $$A = \sum_{i=1}^n f_{ni + n + i}\otimes e_i^T$$
• Of course, I should credit danj grinberg for the index formula, where I've handled the reversal by it being the $(j,i)$th entry that is $1$. – Paul Sinclair Sep 22 '19 at 16:28