matrix_ops.to_density_matrix¶
Converts a row or a column vector to a density matrix.
Functions¶
|
Convert a given vector to a density matrix or return the density matrix if already given. |
Module Contents¶
- matrix_ops.to_density_matrix.to_density_matrix(input_array)¶
Convert a given vector to a density matrix or return the density matrix if already given.
If the input is a vector, this function computes the outer product to form a density matrix. If the input is already a density matrix (square matrix), it returns the matrix as is.
Examples
As an example, consider one of the Bell states.
>>> from toqito.states import bell >>> from toqito.matrix_ops import to_density_matrix >>> >>> to_density_matrix(bell(0)) array([[0.5, 0. , 0. , 0.5], [0. , 0. , 0. , 0. ], [0. , 0. , 0. , 0. ], [0.5, 0. , 0. , 0.5]])
- Raises:
ValueError – If the input is not a vector or a square matrix.
- Parameters:
input_array (numpy.ndarray) – Input array which could be a vector or a density matrix.
- Returns:
The computed or provided density matrix.
- Return type:
numpy.ndarray