dq.unit
unit(x: ArrayLike) -> Array
Normalize a ket, bra or density matrix to unit norm.
The returned object is divided by its norm (see dq.norm()
).
Parameters
-
x
(array_like of shape (..., n, 1) or (..., 1, n) or (..., n, n))
–
Ket, bra or density matrix.
Returns
(array 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)
>>> dq.norm(psi)
Array(1.414, dtype=float32)
>>> psi = dq.unit(psi)
>>> dq.norm(psi)
Array(1., dtype=float32)