Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

NumPy · Function

np.linalg.cholesky

Computes the Cholesky factorization of a square Hermitian positive-definite matrix, returning a lower-triangular factor by default or an upper-triangular factor when requested.

How it works

The function factors a square Hermitian positive-definite matrix into a triangular factor and its conjugate transpose. By default it returns a lower-triangular L satisfying A = L·Lᴴ; setting upper=True returns an upper-triangular U satisfying A = Uᴴ·U. Leading batch dimensions are supported.

Syntax

numpy.linalg.cholesky(a, /, *, upper=False)

Parameters

NameTypeDescription
a(..., M, M) array_likeHermitian (symmetric if real-valued) and positive-definite input matrix with shape (..., M, M).
upperboolSelects the upper-triangular factor when True; otherwise selects the lower-triangular factor. Default: False.

Returns

L (..., M, M) array_like: the lower- or upper-triangular Cholesky factor of a; matrix input produces a matrix object.

Key points

  • The function supports either factor orientation: lower L reconstructs the matrix as L·Lᴴ, while upper U reconstructs it as Uᴴ·U.
  • The selected result is triangular: L has entries only on and below the diagonal, whereas U has entries only on and above it.
  • For complex inputs, ᴴ means conjugate transpose; for real inputs it reduces to the ordinary transpose.
  • Set upper=True to request the upper-triangular factor.
  • Leave upper=False, or omit it, to request the lower-triangular factor.
  • A matrix input preserves matrix-object output rather than necessarily producing an ndarray.

Common mistakes

  • The input must be Hermitian, or symmetric for real-valued data, and positive-definite; otherwise the decomposition is not valid.
  • Only the selected triangle and diagonal participate in the computation, so inconsistent values in the other triangle are ignored.

Example: Compute lower and upper factors

import numpy as np

A = np.array([[4.0, 2.0],
              [2.0, 2.0]])
L = np.linalg.cholesky(A)
U = np.linalg.cholesky(A, upper=True)

assert np.allclose(L @ L.T, A)
assert np.allclose(U.T @ U, A)

Computes both triangular factors and verifies their reconstruction of the positive-definite matrix.

When to use it

Positive-definite linear systems

Solve linear systems with symmetric or Hermitian positive-definite coefficient matrices using triangular solves.

Covariance factorization

Represent covariance matrices through triangular factors for sampling or likelihood calculations.

Batched decompositions

Process several independent square matrices stored in leading batch dimensions.

Interview questions

QWhat does numpy.linalg.cholesky return?

It computes a Cholesky factorization of a square Hermitian positive-definite matrix. With the default, the returned lower-triangular L satisfies A = L·Lᴴ; with upper=True, the returned U satisfies A = Uᴴ·U.

Follow-up: What changes for a real-valued matrix? The conjugate transpose becomes the ordinary transpose, so the identities use L.T or U.T.

QWhat input shapes does the function support?

The a parameter has shape (..., M, M), allowing zero or more leading batch dimensions. Each final two-dimensional slice must be square and meet the Hermitian positive-definite requirement.

Follow-up: How could multiple decompositions be computed? Supply an array whose leading dimensions index the independent square matrices.

QHow does the upper argument affect the result?

upper is a Boolean keyword-only option. False, the default, selects the lower-triangular factor; True selects the upper-triangular factor.

Follow-up: How do you verify an upper factor? Reconstruct the input as Uᴴ·U rather than U·Uᴴ.

  • numpy.linalg.solve
  • numpy.linalg.eigh
  • numpy.linalg.slogdet

Source: numpy.linalg.cholesky. Checked 2026-10-15.