matrix_ops.vector_to_density_matrix

Convert row or column vector to density matrix.

Module Contents

Functions

vector_to_density_matrix(input_array)

Convert a given vector to a density matrix or return the density matrix if already given.

matrix_ops.vector_to_density_matrix.vector_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 vector_to_density_matrix
>>>
>>> vector_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