Maths for ML / Notation

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

diagonal matrix

Linear algebraIntermediate

Say it “diag of v”

A square matrix with v along the diagonal and zeros elsewhere (or the reverse: pull out a matrix's diagonal).

Example

diag⁡(1,2)=[1002]\operatorname{diag}(1,2) = \begin{bmatrix}1&0\\0&2\end{bmatrix}

In code

np.diag(v)
torch.diag(v)

Where you’ll see it in ML

Diagonal covariances, per-feature scaling, SVD's Σ.

Lessons that use it

← All 94 symbols