diag

tenpy.linalg.np_conserved.diag(s, leg, dtype=None)[source]

Returns a square, diagonal matrix of entries s.

The resulting matrix has legs (leg, leg.conj()) and charge 0.

Parameters
sscalar | 1D array

The entries to put on the diagonal. If scalar, all diagonal entries are the same.

legLegCharge

The first leg of the resulting matrix.

dtypeNone | type

The data type to be used for the result. By default, use dtype of s.

Returns
diagonalArray

A square matrix with diagonal entries s.

See also

Array.scale_axis

similar as tensordot(diag(s), ...), but faster.