toqito.matrix_ops.vectors_to_gram_matrix ======================================== .. py:module:: toqito.matrix_ops.vectors_to_gram_matrix .. autoapi-nested-parse:: Calculates the Gram matrix from a list of vectors. Module Contents --------------- .. py:function:: vectors_to_gram_matrix(vectors) Construct the Gram matrix from a list of vectors or density matrices [@WikiGram]. The Gram matrix is a matrix of inner products. This function automatically detects whether the inputs are vectors (pure states) or density matrices (mixed states) and computes the appropriate Gram matrix. For vectors |ψᵢ⟩: G[i, j] = ⟨ψᵢ|ψⱼ⟩ For density matrices ρᵢ: G[i, j] = Tr(ρᵢ ρⱼ) .. rubric:: Examples Example with real vectors: ```python exec="1" source="above" import numpy as np from toqito.matrix_ops import vectors_to_gram_matrix vectors = [np.array([1, 2]), np.array([3, 4])] gram_matrix = vectors_to_gram_matrix(vectors) print(gram_matrix) ``` Example with complex vectors: ```python exec="1" source="above" import numpy as np from toqito.matrix_ops import vectors_to_gram_matrix vectors = [np.array([1+1j, 2+2j]), np.array([3+3j, 4+4j])] gram_matrix = vectors_to_gram_matrix(vectors) print(gram_matrix) ``` Example with density matrices (mixed states): ```python exec="1" source="above" import numpy as np from toqito.matrix_ops import vectors_to_gram_matrix # Two mixed states rho1 = 0.7 * np.array([[1., 0.], [0., 0.]]) + 0.3 * np.eye(2) / 2 rho2 = 0.7 * np.array([[0., 0.], [0., 1.]]) + 0.3 * np.eye(2) / 2 states = [rho1, rho2] gram_matrix = vectors_to_gram_matrix(states) print(gram_matrix) ``` :raises ValueError: If the vectors are not all of the same shape. :param vectors: A list of vectors (1D/column arrays for pure states) or density matrices (2D arrays for mixed states). :returns: The Gram matrix with entries G[i,j] = ⟨vᵢ|vⱼ⟩ for vectors or Tr(ρᵢρⱼ) for density matrices.