Skip to content

dq.todm

todm(x: ArrayLike) -> Array

Returns the density matrix representation of a quantum state.

Note

This function is an alias of dq.proj(). If x is already a density matrix, it is returned directly.

Parameters

  • x (array_like of shape (..., n, 1) or (..., 1, n) or (..., n, n)) –

    Ket, bra or density matrix.

Returns

(array of shape (..., n, n)) Density matrix.

Examples

>>> psi = dq.fock(3, 0)  # shape: (3, 1)
>>> psi
Array([[1.+0.j],
       [0.+0.j],
       [0.+0.j]], dtype=complex64)
>>> dq.todm(psi)  # shape: (3, 3)
Array([[1.+0.j, 0.+0.j, 0.+0.j],
       [0.+0.j, 0.+0.j, 0.+0.j],
       [0.+0.j, 0.+0.j, 0.+0.j]], dtype=complex64)