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$? 

For $x\in{\mathbb R}^{n}\,$ you can express the matrix
$A\in{\mathbb R}^{n^2\times n}\,$ in index notation
$$A_{ij} = \begin{cases}
{\tt1}\quad{\rm if}\;(i+n=j+nj) \\
{\tt0}\quad{\rm otherwise} \\
\end{cases}
$$
This translates verbatim into any language which permits array comprehensions.
For example, to reproduce the matrix in your question, in Julia you could write
n=2; A = [i+n==j+n*j for i=1:n*n, j=1:n] * 1
4×2 Matrix{Int64}:
 1  0
 0  0
 0  0
 0  1

