Python matrix libraries

Updated Nov 2026

Python matrix libraries store matrices and run linear algebra on them, from multiplication and inversion to decompositions and solvers. A sparse format stores only the nonzero entries of a matrix rather than every cell. These libraries let machine learning models, simulations, and data pipelines process large grids of numbers.

Popularity

NumPy has the most monthly downloads in this comparison, at 1.1B.

LibraryMonthly downloadsStarsLast releaseLicense
NumPy
1.1B
33.4KNov 2026BSD-3-Clause AND 0BSD AND MIT AND Zlib AND CC0-1.0
SciPy
392.1M
15.2KAug 2026BSD-3-Clause
SymPy
169.9M
15.1KApr 2025BSD
PyTorch
59.5M
105.6KOct 2026Apache-2.0 AND Apache-2.0 WITH LLVM-exception AND BSD-2-Clause AND BSD-3-Clause AND BSL-1.0 AND ISC AND MIT AND Zlib
Dask Array
31.6M
14.0KAug 2026BSD-3-Clause
JAX
12.8M
36.6KNov 2026Apache-2.0
TensorFlow
12.4M
201.6KMar 2026Apache-2.0
PyTensor
1.5M
654Nov 2026BSD-3-Clause
Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

Libraries and code examples

Computes numerical linear algebra using arrays and BLAS/LAPACK routines.

Downloads / mo
1.1B
Stars
33.4K
Last release
2.5.5
License
BSD-3-Clause AND 0BSD AND MIT AND Zlib AND CC0-1.0

Strengths

  • Uses arrays for matrix products. Use @ for products between two-dimensional arrays.
  • Solves dense linear systems. Call linalg.solve for square systems with independent rows.

Limitations

  • Solve requires full-rank square systems. Use lstsq for least-squares solutions when solve assumptions fail.
  • Matrix class is discouraged. Use two-dimensional arrays for new linear algebra code.
$ pip install numpy
import numpy as np

a = np.array([[1, 2], [3, 5]])

b = np.array([1, 2])

x = np.linalg.solve(a, b)

x

NumPy examples

From open-source projects on GitHub

Provides sparse matrix storage, numerical solvers, and matrix functions.

Downloads / mo
392.1M
Stars
15.2K
Last release
1.18.1
License
BSD-3-Clause

Strengths

  • Solves sparse linear systems. Use spsolve with sparse coefficients and vector or matrix right-hand sides.
  • Computes matrix exponentials. Use expm for the matrix exponential rather than element-wise exponentiation.

Limitations

  • Sparse arrays need sparse-aware operations. Use sparse operations or convert explicitly before applying NumPy functions.
  • Incorrect structure hints corrupt solutions. Only set assume_a when the matrix has the stated structure.
$ pip install scipy
import numpy as np

a = np.array([[3, 2, 0], [1, -1, 0], [0, 5, 1]])

b = np.array([2, 4, -1])

from scipy.linalg import solve

x = solve(a, b)

x

a @ x == b

SciPy examples

From open-source projects on GitHub

Performs matrix algebra with symbolic entries and exact expressions.

Downloads / mo
169.9M
Stars
15.1K
Last release
1.14.0
License
BSD

Strengths

  • Works with symbolic matrix entries. Keep symbolic values in matrix calculations.
  • Returns eigenvalue multiplicities. Use eigenvals for eigenvalues and their algebraic multiplicities.

Limitations

  • Symbolic zeros can be inconclusive. Pass iszerofunc when simplification cannot identify zero entries.
  • Mutable matrices restrict expression use. Use ImmutableMatrix inside expressions that require immutable values.

Quickstart

From matrices.html
$ pip install sympy
from sympy import Matrix

M = Matrix(3, 3, [0, 1, 1, 1, 0, 0, 1, 1, 1])

M.eigenvals()

SymPy examples

From open-source projects on GitHub

Computes linear algebra over tensors, including batches of matrices.

Downloads / mo
59.5M
Stars
105.6K
Last release
2.15.0
License
Apache-2.0 AND Apache-2.0 WITH LLVM-exception AND BSD-2-Clause AND BSD-3-Clause AND BSL-1.0 AND ISC AND MIT AND Zlib

Strengths

  • Solves batches of linear systems. Pass batched matrices to linalg.solve instead of looping over each system.
  • Offers compressed sparse tensor layouts. Store sparse matrices using supported coordinate or compressed layouts.

Limitations

  • Sparse operator coverage is incomplete. Check that the selected sparse layout supports the required operation.
  • Eigenvector gradients need distinct eigenvalues. Repeated eigenvalues prevent finite eigenvector gradients.
$ pip install torch
import torch

A = torch.randn(3, 3)
b = torch.randn(3)
x = torch.linalg.solve(A, b)
print(x)

PyTorch examples

From open-source projects on GitHub

Runs PyData workloads in parallel with task scheduling.

Downloads / mo
31.6M
Stars
14.0K
Last release
2026.8.0
License
BSD-3-Clause

Quickstart

From array-api.html
$ pip install "dask[array]"
import dask.array as da

x = da.eye(2, chunks=2)
u, s, v = da.linalg.svd(x)
print(s.compute())

Dask Array examples

From open-source projects on GitHub

Differentiates, compiles, and transforms NumPy code.

Downloads / mo
12.8M
Stars
36.6K
Last release
0.12.1
License
Apache-2.0
$ pip install jax
import jax.numpy as jnp

x = jnp.array([[1., 2., 3.], [4., 5., 7.]])
print(jnp.linalg.norm(x))

JAX examples

From open-source projects on GitHub
def operator_to_matrix(operator_fn, problem):
    """Only used for when debugging.
    Can be used to print the matrix, check the conditional number, etc.
    """
    J = jax.jacfwd(operator_fn)(np.zeros(problem.num_total_dofs_all_vars))
    return J

Provides an open source machine learning framework.

Downloads / mo
12.4M
Stars
201.6K
Last release
2.21.0
License
Apache-2.0

Quickstart

From README.md
$ pip install tensorflow
import tensorflow as tf

a = tf.constant([[1., 2.], [3., 4.]])
print(tf.linalg.matmul(a, a))

TensorFlow examples

From open-source projects on GitHub

Compiles mathematical expressions for evaluation on CPUs and GPUs.

Downloads / mo
1.5M
Stars
654
Last release
3.3.8
License
BSD-3-Clause

Quickstart

From linalg.html
$ pip install pytensor
import pytensor
import pytensor.tensor as pt

x = pt.matrix("x")
f = pytensor.function([x], pt.linalg.det(x))
print(f([[1., 2.], [3., 4.]]))

FAQ

NumPy suits dense matrices on the CPU. SciPy suits sparse matrices and adds solvers that work on them. PyTorch and JAX suit matrix work on GPUs and other accelerators.

NumPy multiplies two arrays as matrices with the @ operator or the matmul function.

NumPy represents a matrix as a two-dimensional ndarray, the same array type it uses for every other shape.

SciPy provides sparse arrays and matrices in several storage formats, each with its own operations. The legacy csr_matrix class remains documented alongside the newer sparse arrays.

For coding agents

Found your matrix library? Help your agent use it.

Connect Exa so your coding agent can find the library’s documentation, check its API, and look up implementations while you build.

Run in your terminal

claude plugin install exa@claude-plugins-official