A Gram matrix is a square matrix whose entries are the pairwise inner products of a finite ordered collection of vectors. It converts geometric information about vectors into algebraic information about a single matrix. Gram matrices connect linear algebra with geometry, least-squares problems, and kernel-based learning. Their defining structural property is positive semidefiniteness; conversely, every Hermitian positive semidefinite matrix admits a representation as a Gram matrix. (people.cs.uchicago.edu)
Definition and conventions
Let belong to a real or complex vector space equipped with an inner product. Using the convention that a complex inner product is conjugate-linear in its first argument and linear in its second, their Gram matrix is
Thus, the diagonal entries are squared lengths, while the off-diagonal entries describe pairwise inner products. The vectors need not be distinct, independent, or a basis. (bpb-us-e1.wpmucdn.com)
If the vectors are columns of a coordinate matrix , expressed in orthonormal coordinates, then
where denotes the conjugate transpose. For real coordinates this becomes , using the ordinary transpose. Authors who take complex inner products to be linear in the first argument may reverse the indices in the definition so that the same matrix formula holds. Stating the convention prevents apparent discrepancies between formulas. (people.cs.uchicago.edu)
The construction also applies to vectors in an infinite-dimensional Hilbert space: any finite collection still produces a finite matrix. (bpb-us-e1.wpmucdn.com)
Positivity, rank, and realization
Conjugate symmetry of the inner product gives , so a Gram matrix is Hermitian, or symmetric in the real case. For any coefficient vector ,
This identity proves positive semidefiniteness and relates the matrix directly to linear combinations of the original vectors. It is a positive definite matrix precisely when the vectors satisfy linear independence. All its eigenvalues are therefore nonnegative. (people.cs.uchicago.edu)
Moreover,
Thus, matrix rank measures the dimension of their linear span, not the number of listed vectors. In coordinates, , because . (bpb-us-e1.wpmucdn.com)
Conversely, the spectral theorem gives a factorization for any Hermitian positive semidefinite matrix. Setting yields ; the columns of realize the required vectors. Removing zero-eigenvalue rows gives a realization in dimension , the smallest possible dimension. (people.cs.uchicago.edu)
Geometric information and determinant
For real vectors in Euclidean space, Gram entries determine lengths and angles:
where the angle formula requires both vectors to be nonzero. They also determine squared pairwise distances:
Consequently, a Gram matrix encodes the geometry of the vectors relative to the origin without specifying their absolute orientation. (tropp.caltech.edu)
The determinant , called the Gram determinant, equals the square of the -dimensional volume of the parallelotope generated by real Euclidean vectors:
A zero determinant indicates linear dependence and zero -dimensional volume. For two vectors, this reduces to
the squared area of their parallelogram. (pmc.ncbi.nlm.nih.gov)
For example, take and . Direct substitution gives
Their lengths are and , their angle is , and the parallelogram has area .
Coordinates and changes of basis
When the vectors form a basis, the Gram matrix represents the inner product in that basis. If and are coordinate columns, then
An orthonormal basis has Gram matrix equal to the identity. For a new basis obtained through an invertible coordinate matrix , the matrix transforms by
This is a congruence transformation, rather than the similarity transformation used for a linear operator. It preserves positive definiteness but need not preserve individual eigenvalues. (cis.upenn.edu)
Least squares and numerical computation
In ordinary least squares, minimizing leads to the normal equations
Their coefficient matrix is the Gram matrix of the columns of . Independent columns make it invertible and ensure a unique minimizer. (stanford.edu)
The singular value decomposition shows that the eigenvalues of are the squared singular values of . For full column rank,
This squaring of the condition number explains why explicitly forming normal equations can amplify numerical difficulties. QR decomposition and singular value decomposition provide alternative least-squares formulations that avoid this squaring. (physbam.stanford.edu)
Kernel methods
In machine learning, a kernel method forms a Gram matrix through a feature map :
Evaluating directly can avoid constructing the feature vectors explicitly. For a valid positive semidefinite kernel, every finite sample produces a positive semidefinite Gram matrix. In a support vector machine, the training inputs enter the dual optimization problem through these pairwise kernel values, allowing nonlinear feature-space geometry to be handled through a finite matrix. (web.stanford.edu)