# cirq.density_matrix_from_state_vector¶

cirq.density_matrix_from_state_vector(state: Sequence, indices: Iterable[int] = None) → numpy.ndarray[source]

Returns the density matrix of the wavefunction.

Calculate the density matrix for the system on the given qubit indices,
with the qubits not in indices that are present in state traced out. If
indices is None the full density matrix for state is returned. We assume
state follows the standard Kronecker convention of numpy.kron.

For example:

::

state = np.array([1/np.sqrt(2), 1/np.sqrt(2)], dtype=np.complex64) indices = None

gives us

$$\rho = \begin{bmatrix} 0.5 & 0.5 0.5 & 0.5 \end{bmatrix}$$

Parameters: state – A sequence representing a wave function in which the ordering mapping to qubits follows the standard Kronecker convention of numpy.kron. indices – list containing indices for qubits that you would like to include in the density matrix (i.e.) qubits that WON’T be traced out. follows the standard Kronecker convention of numpy.kron. A numpy array representing the density matrix. ValueError – if the size of state is not a power of 2. ValueError – if the size of the state represents more than 25 qubits. IndexError – if the indices are out of range for the number of qubits corresponding to the state.