Skip to content

dq.unit

unit(x: QArrayLike) -> QArray

Normalize a ket, bra or density matrix to unit norm.

The returned object is divided by its norm (see dq.norm()).

Parameters

  • x (qarray-like of shape (..., n, 1) or (..., 1, n) or (..., n, n)) –

    Ket, bra or density matrix.

Returns

(qarray of shape (..., n, 1) or (..., 1, n) or (..., n, n)) Normalized ket, bra or density matrix.

Examples

>>> psi = dq.fock(4, 0) + dq.fock(4, 1)
>>> psi.norm()
Array(1.414, dtype=float32)
>>> psi = dq.unit(psi)
>>> psi.norm()
Array(1., dtype=float32)