dq.norm
norm(x: ArrayLike) -> Array
Returns the norm of a ket, bra or density matrix.
For a ket or a bra, the returned norm is \(\sqrt{\braket{\psi|\psi}}\). For a density matrix, it is \(\tr{\rho}\).
Parameters
-
x
(array_like of shape (..., n, 1) or (..., 1, n) or (..., n, n))
–
Ket, bra or density matrix.
Returns
(array of shape (...)) Real-valued norm of x
.
Raises
-
ValueError
–If
x
is not a ket, bra or density matrix.
Examples
For a ket:
>>> psi = dq.fock(4, 0) + dq.fock(4, 1)
>>> dq.norm(psi)
Array(1.414, dtype=float32)
For a density matrix:
>>> rho = dq.fock_dm(4, 0) + dq.fock_dm(4, 1) + dq.fock_dm(4, 2)
>>> dq.norm(rho)
Array(3., dtype=float32)