TITLE: vector to diagonal matrix
QUESTION [19 upvotes]: For any column vector we can easily create a corresponding diagonal matrix, whose elements along the diagonal are the elements of the column vector.
Is there a simple way to write this transformation using standard linear algebra operations (such as matrix multiplication, etc.), instead of explicitly writing it as $diag(\mathbf{x})$?
For example $M \mathbf{x}$ cannot work for any matrix M, since the result will be a vector, not a diagonal matrix. But maybe there is some more elaborate expression that yields the diagonal matrix.

REPLY [14 votes]: I'm not sure whether it answers your question, but here is a "matrix procedure" to transform the column vector $v$ into a diagonal matrix $D$:
Let $E_i$ be the $n \times n$ matrix with a $1$ on position $(i,i)$ and zeros everywhere else; similarly, let $e_i$ be the $1 \times n$ row matrix with a $1$ on position $(1,i)$ and zeros everywhere else. Then
$$D = \sum_{i=1}^n E_i v e_i .$$