Gram Matrix Calculator

Stephanie Ben-Joseph headshot Stephanie Ben-Joseph

What is a Gram matrix?

A Gram matrix (also called a Gramian) captures how a collection of vectors relates through their inner products. If you have vectors v1,v2,,vn in a real inner product space, the Gram matrix G is the n×n matrix whose (i,j)-entry is the inner product of the i-th and j-th vectors.

In symbols, the entries are defined by

g_ij = vi , vj

For real column vectors this inner product is just the dot product, so you can think of each entry as gij=vivj. The matrix is always symmetric (because vivj=vjvi) and positive semi-definite, which means all its eigenvalues are non-negative.

Geometrically, the diagonal entries gii give the squared lengths of the vectors, while the off-diagonal entries encode the cosines of angles between them. This makes the Gram matrix a compact summary of lengths, angles, and linear dependence in a set of vectors.

How to use this Gram matrix calculator

Follow these steps to compute the Gram matrix for up to four vectors:

You can interpret the result as a summary of how similar your vectors are. Large positive off-diagonal entries indicate that two vectors point in a similar direction, while small or zero entries suggest they are nearly orthogonal.

Formula for the Gram matrix of vectors

Suppose you enter n vectors v1,,vn, each living in Rd. Write each vector as vi=(vi1,vi2,,vid). The dot product of two vectors vi and vj is

vivj=k=1dvikvjk.

The Gram matrix G is then the n×n matrix whose entries are

g_ij=vivj, 1i,jn.

In matrix form, if you arrange your vectors as columns of a matrix Vd×n, then the Gram matrix is simply G=V&TopV. Many algorithms in linear algebra, statistics, and machine learning rely on this construction.

Worked example

Consider two vectors in R3:

v1=(1,2,3), v2=(4,5,6).

Compute their dot products:

The Gram matrix for v1,v2 is therefore

G=14323277.

The diagonal entries (14 and 77) are the squared lengths v12 and v22. The off-diagonal entries (both 32) measure how aligned the vectors are. If v1 and v2 were orthogonal, these entries would be zero.

The determinant of this Gram matrix, detG, is the squared area of the parallelogram spanned by v1 and v2. A determinant of zero would indicate that the vectors are linearly dependent.

Interpreting the Gram matrix

Once you have computed a Gram matrix, you can read several geometric and algebraic properties directly from it:

Gram matrix vs related matrices

The Gram matrix is closely related to other common matrices in linear algebra and statistics. The table below summarizes some key differences.

Matrix type Definition Captures Typical use cases
Gram matrix G=V&TopV for a matrix of vectors V Inner products, lengths, angles, linear independence Geometry of vector sets, kernel methods, basis analysis
Covariance matrix Centered Gram matrix scaled by sample size Variances and covariances of random variables Statistics, data analysis, PCA
Kernel (Gram) matrix Entries k(xi,xj) from a kernel function Similarities in an implicit feature space Support vector machines, Gaussian processes, kernel PCA

In fact, many authors refer to a kernel matrix as a Gram matrix computed in a higher-dimensional feature space. The calculator on this page works with explicit real-valued vectors and the standard dot product.

Applications of Gram matrices

Gram matrices appear in many areas of mathematics, data science, and engineering:

Assumptions and limitations of this calculator

This online tool is designed to be simple and educational. Keep the following assumptions and limitations in mind when interpreting the results:

Within these limits, the tool gives a quick and transparent way to explore inner products, lengths, angles, and independence among a small set of vectors.

Common questions

What is a Gram matrix used for?

A Gram matrix summarizes all pairwise inner products of a set of vectors. It is used to study the geometry of vectors (lengths, angles, volumes), analyze linear independence, and form the basis of many algorithms in statistics and machine learning.

How is a Gram matrix different from a covariance matrix?

A covariance matrix measures how random variables vary together and is built from centered data, while a Gram matrix is just the inner products of raw vectors. For data points arranged as rows of a matrix, the covariance matrix is a centered, rescaled version of the Gram matrix.

Can this calculator handle complex vectors?

No. This tool assumes all components are real numbers and uses the standard dot product. For complex vectors one would use the Hermitian inner product, which conjugates one of the vectors; that generalization is not implemented here.

Enter vectors to see their Gram matrix.

Embed this calculator

Copy and paste the HTML below to add the Gram Matrix Calculator (Gramian) – Compute Inner Products of Vectors to your website.