dq.unit
unit(x: QArrayLike, *, psd: bool = True) -> QArray
Normalize a ket, bra, density matrix or Hermitian 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.
-
psd–Whether
xis a positive semi-definite matrix (seedq.norm()).
Returns:
-
(qarray of shape (..., n, 1) or (..., 1, n) or (..., n, n))
–
Normalized ket, bra or density matrix.
See also
dq.norm(): returns the norm of a ket, bra, density matrix, or Hermitian 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)