{
  "id": "gram-matrix",
  "title": "Gram matrix",
  "lang": "en",
  "source_lang": "en",
  "summary": "A Gram matrix records pairwise inner products of vectors, encoding their lengths, angles, linear dependence, and associated geometric volumes.",
  "category": "mathematics",
  "subcategory": "algebra",
  "type": "concept",
  "aliases": [
    "Gramian matrix"
  ],
  "generated_at": "2026-10-04",
  "model": "pro/gpt-6.1-sol",
  "url": "https://aiwiki.page/en/gram-matrix/",
  "translations": {
    "zh-Hans": {
      "url": "https://aiwiki.page/zh/gram-matrix/",
      "json": "https://aiwiki.page/zh/gram-matrix.json"
    }
  },
  "sections": [
    {
      "heading": "",
      "text": "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)"
    },
    {
      "heading": "Definition and conventions",
      "text": "Let \\(v_1,\\ldots,v_n\\) 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\n\n\\[G_{ij}=\\langle v_i,v_j\\rangle, \\qquad 1\\leq i,j\\leq n.\\]\n\nThus, 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)\n\nIf the vectors are columns of a coordinate matrix \\(A\\), expressed in orthonormal coordinates, then\n\n\\[G=A^*A,\\]\n\nwhere \\(A^*\\) denotes the conjugate transpose. For real coordinates this becomes \\(G=A^{\\mathsf T}A\\), 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)\n\nThe construction also applies to vectors in an infinite-dimensional Hilbert space: any finite collection still produces a finite matrix. (bpb-us-e1.wpmucdn.com)"
    },
    {
      "heading": "Positivity, rank, and realization",
      "text": "Conjugate symmetry of the inner product gives \\(G^*=G\\), so a Gram matrix is Hermitian, or symmetric in the real case. For any coefficient vector \\(c\\),\n\n\\[c^*Gc = \\left\\|\\sum_{i=1}^{n}c_i v_i\\right\\|^2 \\geq 0.\\]\n\nThis 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)\n\nMoreover,\n\n\\[\\operatorname{rank}(G) = \\dim\\operatorname{span}\\{v_1,\\ldots,v_n\\}.\\]\n\nThus, matrix rank measures the dimension of their linear span, not the number of listed vectors. In coordinates, \\(\\ker(A^*A)=\\ker(A)\\), because \\(c^*A^*Ac=\\|Ac\\|^2\\). (bpb-us-e1.wpmucdn.com)\n\nConversely, the spectral theorem gives a factorization \\(G=U\\Lambda U^*\\) for any Hermitian positive semidefinite matrix. Setting \\(B=\\Lambda^{1/2}U^*\\) yields \\(G=B^*B\\); the columns of \\(B\\) realize the required vectors. Removing zero-eigenvalue rows gives a realization in dimension \\(\\operatorname{rank}(G)\\), the smallest possible dimension. (people.cs.uchicago.edu)"
    },
    {
      "heading": "Geometric information and determinant",
      "text": "For real vectors in Euclidean space, Gram entries determine lengths and angles:\n\n\\[\\|v_i\\|=\\sqrt{G_{ii}}, \\qquad \\cos\\theta_{ij} = \\frac{G_{ij}}{\\sqrt{G_{ii}G_{jj}}},\\]\n\nwhere the angle formula requires both vectors to be nonzero. They also determine squared pairwise distances:\n\n\\[\\|v_i-v_j\\|^2 = G_{ii}+G_{jj}-2G_{ij}.\\]\n\nConsequently, a Gram matrix encodes the geometry of the vectors relative to the origin without specifying their absolute orientation. (tropp.caltech.edu)\n\nThe determinant \\(\\det G\\), called the Gram determinant, equals the square of the \\(n\\)-dimensional volume of the parallelotope generated by \\(n\\) real Euclidean vectors:\n\n\\[V=\\sqrt{\\det G}.\\]\n\nA zero determinant indicates linear dependence and zero \\(n\\)-dimensional volume. For two vectors, this reduces to\n\n\\[\\det G = \\|v_1\\|^2\\|v_2\\|^2-\\langle v_1,v_2\\rangle^2,\\]\n\nthe squared area of their parallelogram. (pmc.ncbi.nlm.nih.gov)\n\nFor example, take \\(v_1=(1,0)\\) and \\(v_2=(1,1)\\). Direct substitution gives\n\n\\[G= \\begin{pmatrix} 1&1\\\\ 1&2 \\end{pmatrix}, \\qquad \\det G=1.\\]\n\nTheir lengths are \\(1\\) and \\(\\sqrt2\\), their angle is \\(45^\\circ\\), and the parallelogram has area \\(1\\)."
    },
    {
      "heading": "Coordinates and changes of basis",
      "text": "When the vectors form a basis, the Gram matrix represents the inner product in that basis. If \\(x\\) and \\(y\\) are coordinate columns, then\n\n\\[\\langle x,y\\rangle_G=x^*Gy.\\]\n\nAn orthonormal basis has Gram matrix equal to the identity. For a new basis obtained through an invertible coordinate matrix \\(P\\), the matrix transforms by\n\n\\[G_{\\mathrm{new}}=P^*GP.\\]\n\nThis 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)"
    },
    {
      "heading": "Least squares and numerical computation",
      "text": "In ordinary least squares, minimizing \\(\\|Ax-b\\|^2\\) leads to the normal equations\n\n\\[A^*Ax=A^*b.\\]\n\nTheir coefficient matrix is the Gram matrix of the columns of \\(A\\). Independent columns make it invertible and ensure a unique minimizer. (stanford.edu)\n\nThe singular value decomposition shows that the eigenvalues of \\(A^*A\\) are the squared singular values of \\(A\\). For full column rank,\n\n\\[\\kappa_2(A^*A)=\\kappa_2(A)^2.\\]\n\nThis 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)"
    },
    {
      "heading": "Kernel methods",
      "text": "In machine learning, a kernel method forms a Gram matrix through a feature map \\(\\phi\\):\n\n\\[K_{ij}=k(x_i,x_j) = \\langle\\phi(x_i),\\phi(x_j)\\rangle.\\]\n\nEvaluating \\(k\\) 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)"
    }
  ],
  "links": [
    "matrix",
    "inner-product",
    "linear-algebra",
    "vector-space",
    "conjugate-transpose",
    "matrix-transpose",
    "hilbert-space",
    "linear-combination",
    "positive-definite-matrix",
    "linear-independence",
    "eigenvalues-and-eigenvectors",
    "matrix-rank",
    "linear-span",
    "spectral-theorem",
    "euclidean-space",
    "determinant",
    "basis-linear-algebra",
    "orthonormal-basis",
    "ordinary-least-squares",
    "singular-value-decomposition",
    "condition-number",
    "qr-decomposition",
    "machine-learning",
    "kernel-method",
    "support-vector-machine"
  ],
  "sources": [
    {
      "title": "people.cs.uchicago.edu/~laci/DMmaxi.pdf",
      "url": "https://people.cs.uchicago.edu/~laci/DMmaxi.pdf"
    },
    {
      "title": "bpb-us-e1.wpmucdn.com/blogs.rice.edu/dist/6/12079/files/2022/12/Youjiang_Xu.pdf",
      "url": "https://bpb-us-e1.wpmucdn.com/blogs.rice.edu/dist/6/12079/files/2022/12/Youjiang_Xu.pdf"
    },
    {
      "title": "tropp.caltech.edu/papers/TDHS05-Designing-Structured-preprint.pdf",
      "url": "https://tropp.caltech.edu/papers/TDHS05-Designing-Structured-preprint.pdf"
    },
    {
      "title": "pmc.ncbi.nlm.nih.gov/articles/PMC7442219/",
      "url": "https://pmc.ncbi.nlm.nih.gov/articles/PMC7442219/"
    },
    {
      "title": "cis.upenn.edu/~jean/math-deep.pdf",
      "url": "https://www.cis.upenn.edu/~jean/math-deep.pdf"
    },
    {
      "title": "stanford.edu/~boyd/vmls/vmls.pdf",
      "url": "https://stanford.edu/~boyd/vmls/vmls.pdf"
    },
    {
      "title": "physbam.stanford.edu/papers/stanford2024-cs205l.pdf",
      "url": "https://physbam.stanford.edu/papers/stanford2024-cs205l.pdf"
    },
    {
      "title": "web.stanford.edu/class/stats202/notes/Support-vector-machines/Kernels.html",
      "url": "https://web.stanford.edu/class/stats202/notes/Support-vector-machines/Kernels.html"
    }
  ],
  "license": "https://creativecommons.org/licenses/by/4.0/"
}