As with any linear mapping, the function $F:\mathbb R^n \to \mathbb R^{n\times n}$ that sends a vector $\vec v = (v_1,\ldots,v_n)$ to a diagonal matrix with those entries:
$$ F\, \vec v = \begin{pmatrix} v_1 & & 0 \\ & \ddots & \\ 0 & & v_n \end{pmatrix} $$
is uniquely determined by its action on a basis. With a suitable choice of notation we can turn such a definition into a "formula".
Recall the standard ordered basis for $\mathbb R^n$, namely row vectors:
$$ \textbf e_1 = (1,0,\ldots,0), \ldots, \textbf e_n = (0,\ldots,0,1) $$
We can then define our linear mapping as a sum:
$$ F(v_1,\ldots,v_n) = \sum_{k=1}^n v_k \textbf e_k^T \textbf e_k $$
Note that the product of column vector $\textbf e_k^T$ and the row vector $\textbf e_k$ gives a diagonal $n\times n$ matrix with $1$ in the $k$th diagonal position (and zeros elsewhere). Therefore the summation of these terms gives a diagonal matrix supplying exactly the specified diagonal entries.
Diag()
operator for a vector $v$ can be written in terms of the identity matrix $I$ and the all-ones vector ${\tt1}$ $$\operatorname{Diag}(v) = I\odot\left(v{\tt1}^T\right)$$ It can also be as the dot product of the vector with a special third-order tensor $$\eqalign{{\cal H}_{ijk} &= \begin{cases} 1 \quad&{\rm if\;} i=j=k \\ 0 \quad&{\rm otherwise} \\ \end{cases}\\ {\rm Diag}(v) &= {\cal H}\cdot v \\&= v\cdot {\cal H} }$$ $\endgroup$