matrix_ops.vectors_to_gram_matrix
Gram matrix from list of vectors.
Module Contents
Functions
|
Construct the Gram matrix from a list of vectors [1]. |
- matrix_ops.vectors_to_gram_matrix.vectors_to_gram_matrix(vectors)
Construct the Gram matrix from a list of vectors [1].
The Gram matrix is a matrix of inner products, where the entry G[i, j] is the inner product of vectors[i] and vectors[j]. This function computes the Gram matrix for a given list of vectors.
Examples
>>> # Example with real vectors: >>> vectors = [np.array([1, 2]), np.array([3, 4])] >>> gram_matrix = vectors_to_gram_matrix(vectors) >>> gram_matrix array([[ 5., 11.], [11., 25.]])
>>> # Example with complex vectors: >>> vectors = [np.array([1+1j, 2+2j]), np.array([3+3j, 4+4j])] >>> gram_matrix = vectors_to_gram_matrix(vectors) >>> gram_matrix array([[ 10.+0.j, 20.+0.j], [ 20.+0.j, 40.+0.j]])
References
- Raises:
ValueError – If the vectors are not all of the same length.
- Parameters:
vectors (list[numpy.ndarray]) – A list of vectors (1D numpy arrays). All vectors must be of the same length.
- Returns:
A list of vectors corresponding to the ensemble of states.
- Return type:
numpy.ndarray