Skip to content

dq.todm

todm(x: QArrayLike) -> QArray

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 (qarray-like of shape (..., n, 1) or (..., 1, n) or (..., n, n)) –

    Ket, bra or density matrix.

Returns

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

Examples

>>> psi = dq.fock(3, 0)  # shape: (3, 1)
>>> psi
QArray: shape=(3, 1), dims=(3,), dtype=complex64, layout=dense
[[1.+0.j]
 [0.+0.j]
 [0.+0.j]]
>>> dq.todm(psi)  # shape: (3, 3)
QArray: shape=(3, 3), dims=(3,), dtype=complex64, layout=dense
[[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]]