Vectors and matrices

diag⁡(v)\operatorname{diag}(\mathbf{v}) Diag

Build a diagonal matrix from a vector, or pull out the diagonal of a matrix.

In ML papers

diag⁡(v)\operatorname{diag}(\mathbf{v}) with a vector inside builds a diagonal matrix with v\mathbf{v} on the diagonal and zeros elsewhere; multiplying by it scales each coordinate, the same as v⊙\mathbf{v} \odot. With a matrix inside, diag⁡(A)\operatorname{diag}(A) usually means the vector of its diagonal entries. Diagonal covariances, N(μ,diag⁡(σ2))\mathcal{N}(\boldsymbol{\mu}, \operatorname{diag}(\boldsymbol{\sigma}^2)), are everywhere in VAEs.

How to type it

LaTeXShows
\operatorname{diag}(\mathbf{v})diag⁡(v)\operatorname{diag}(\mathbf{v})

A worked example

diag⁡(2,5)=(2005)\operatorname{diag}(2, 5) = \begin{pmatrix} 2 & 0 \\ 0 & 5 \end{pmatrix}

Equations that use it

Related

In\mathbf{I}_nIdentity matrixa⊙b\mathbf{a} \odot \mathbf{b}Hadamard (elementwise) productΣ\SigmaSigma (capital)

Decode this example →