# Python math libraries

Python math libraries extend the language's built-in numbers with arrays, symbolic algebra, and arbitrary-precision arithmetic. A computer algebra system keeps expressions exact rather than rounding each step to a floating-point value. These libraries let researchers, engineers, and AI agents run numerical and symbolic calculations in Python.

## Popularity

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [NumPy](#numpy) | 1.1B | 33.4K | Nov 2026 | BSD-3-Clause AND 0BSD AND MIT AND Zlib AND CC0-1.0 |
| [SciPy](#scipy) | 392.1M | 15.2K | Aug 2026 | BSD-3-Clause |
| [SymPy](#sympy) | 169.9M | 15.1K | Apr 2025 | BSD |
| [mpmath](#mpmath) | 168.4M | 1.2K | Mar 2026 | BSD-3-Clause |
| [PyTorch](#torch) | 59.5M | 105.6K | Oct 2026 | 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 |
| [Dask](#dask) | 31.6M | 14.0K | Aug 2026 | BSD-3-Clause |
| [NumExpr](#numexpr) | 14.4M | 2.5K | Jul 2026 | MIT |
| [JAX](#jax) | 12.8M | 36.6K | Nov 2026 | Apache-2.0 |

Downloads: PyPI, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[NumPy](#numpy) has the most monthly downloads in this comparison, at 1.1B.

## Capabilities

| Library | Adjustable decimal precision | Sparse matrix storage |
| --- | --- | --- |
| [NumPy](#numpy) | No | No |
| [SciPy](#scipy) | No | Yes |
| [SymPy](#sympy) | Yes | Yes |
| [mpmath](#mpmath) | Yes | Yes |
| [PyTorch](#torch) | No | Yes |
| [Dask](#dask) | No | Via plugin |
| [NumExpr](#numexpr) | No | No |
| [JAX](#jax) | No | Yes |

## Libraries

### NumPy

[GitHub](https://github.com/numpy/numpy) · [PyPI](https://pypi.org/project/numpy) · [Docs](https://numpy.org/doc/stable/reference/routines.linalg.html)

Provides multidimensional arrays and operations for numerical computing.

- 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
- Capabilities: [From the NumPy docs](https://numpy.org/doc/stable/reference/routines.linalg.html)

**Strengths**

- **Calculates whole arrays elementwise.** Apply mathematical operations to array elements with broadcasting.
- **Integrates sampled data.** Use trapezoid to integrate values sampled along an axis.

**Watch out for**

- **Fixed-width integers can overflow.** Choose a data type large enough for intermediate and final values.
- **Negative real roots return NaN.** Use complex inputs when square roots need complex results.

```sh
pip install numpy
```

**scikit-learn/scikit-learn** (68.2K stars)

[scikit-learn/scikit-learn](https://github.com/scikit-learn/scikit-learn) 

```python
def row_norms(X, squared=False):
    """Row-wise (squared) Euclidean norm of X.

    Equivalent to np.sqrt((X * X).sum(axis=1)), but also supports sparse
    matrices and does not create an X.shape-sized temporary.

    Performs no input validation.

    Parameters
    ----------
    X : array-like
        The input array.
    squared : bool, default=False
        If True, return squared norms.

    Returns
    -------
    array-like
        The row-wise (squared) Euclidean norm of X.
    """
    if sparse.issparse(X):
        X = X.tocsr()
        norms = csr_row_norms(X)
        if not squared:
            norms = np.sqrt(norms)
    else:
        xp, _ = get_namespace(X)
        if _is_numpy_namespace(xp):
            X = np.asarray(X)
            norms = np.einsum("ij,ij->i", X, X)
            norms = xp.asarray(norms)
        else:
            norms = xp.sum(xp.multiply(X, X), axis=1)
        if not squared:
            norms = xp.sqrt(norms)
    return norms

```

[sklearn/utils/extmath.py](https://github.com/scikit-learn/scikit-learn/blob/a30a70e39ef550a01ea7234e9cf10d3d821df9cd/sklearn/utils/extmath.py#L58-L93) · [More projects using NumPy →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20numpy%20for%20scalar%20geometry%20vector%20normalization%20filtering%20quadrature%20and%20arbitrary-precision%20conversion&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
import numpy as np

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

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

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

x

```

From [quickstart.html](https://numpy.org/doc/stable/reference/generated/numpy.linalg.solve.html)

### SciPy

[GitHub](https://github.com/scipy/scipy) · [PyPI](https://pypi.org/project/scipy) · [Docs](https://docs.scipy.org/doc/scipy/reference/linalg.html)

Provides numerical algorithms and scientific-computing tools built on NumPy.

- Downloads / mo: 392.1M
- Stars: 15.2K
- Last release: 1.18.1
- License: BSD-3-Clause
- Capabilities: [From the SciPy docs](https://docs.scipy.org/doc/scipy/reference/linalg.html)

**Strengths**

- **Integrates callable functions.** Use quad to compute a definite integral of a callable.
- **Approximates callable derivatives.** Use differentiate.derivative to estimate a callable’s derivative.

**Watch out for**

- **Sharp features can be missed.** Pulses narrow relative to the integration interval can be integrated incorrectly.
- **Returned errors are estimates.** Treat quad’s reported absolute error as an estimate.

```sh
pip install scipy
```

**deepmodeling/jax-fem** (784 stars)

[deepmodeling/jax-fem](https://github.com/deepmodeling/jax-fem) 

```python
def scipy_spsolve(A, b):
    logger.debug("Scipy Solver - Solving linear system with scipy.sparse.linalg.spsolve")
    indptr, indices, data = A.getValuesCSR()
    Asp = scipy.sparse.csr_matrix((data, indices, indptr))
    # SciPy's spsolve uses UMFPACK only when scikits.umfpack is installed and
    # applicable; otherwise it falls back to SuperLU.
    x = scipy.sparse.linalg.spsolve(Asp, onp.array(b))

    # TODO: try https://jax.readthedocs.io/en/latest/_autosummary/jax.experimental.sparse.linalg.spsolve.html
    # x = jax.experimental.sparse.linalg.spsolve(av, aj, ai, b)

    logger.debug("Scipy Solver - Finished solving, linear solve res = %.3g",
                 np.linalg.norm(Asp @ x - b))
    return x

```

[jax_fem/solver.py](https://github.com/deepmodeling/jax-fem/blob/01d11bdb57aa76dcfe7189e0e77d067960c2a6ac/jax_fem/solver.py#L89-L102) · [More projects using SciPy →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20scipy%20for%20scalar%20geometry%20vector%20normalization%20filtering%20quadrature%20and%20arbitrary-precision%20conversion&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```python
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

```

From [integrate.html](https://docs.scipy.org/doc/scipy/reference/generated/scipy.linalg.solve.html)

### SymPy

[GitHub](https://github.com/sympy/sympy) · [PyPI](https://pypi.org/project/sympy) · [Docs](https://docs.sympy.org/latest/modules/matrices/matrices.html)

Performs computer algebra in Python.

- Downloads / mo: 169.9M
- Stars: 15.1K
- Last release: 1.14.0
- License: BSD
- Capabilities: [From the SymPy docs](https://docs.sympy.org/latest/modules/matrices/matrices.html)

```sh
pip install sympy
```

**Phylliade/ikpy** (1.0K stars)

[Phylliade/ikpy](https://github.com/Phylliade/ikpy) 

```python
def _apply_geometric_transformations(self, theta, mu, symbolic):

    if symbolic:
        # Angle symbolique qui paramètre la rotation du joint en cours
        symbolic_frame_matrix = np.eye(4)

        # Apply translation matrix
        symbolic_frame_matrix = symbolic_frame_matrix * sympy.Matrix(geometry.homogeneous_translation_matrix(*self.origin_translation))

        # Apply orientation matrix
        symbolic_frame_matrix = symbolic_frame_matrix * geometry.cartesian_to_homogeneous(geometry.rpy_matrix(*self.origin_orientation))

        # Apply rotation matrix
        if self.has_rotation:
            symbolic_frame_matrix = symbolic_frame_matrix * geometry.cartesian_to_homogeneous(geometry.symbolic_axis_rotation_matrix(self.rotation, theta), matrix_type="sympy")

        # Apply translation
        if self.has_translation:
            translation_vector = self.translation * mu
            symbolic_frame_matrix = symbolic_frame_matrix * geometry.get_symbolic_translation_matrix(translation_vector)

        symbolic_frame_matrix = sympy.lambdify([theta, mu], symbolic_frame_matrix, "numpy")

        return symbolic_frame_matrix

    else:
        # Init the transformation matrix
        frame_matrix = np.eye(4)

        # First, apply translation matrix
        frame_matrix = np.dot(frame_matrix, geometry.homogeneous_translation_matrix(*self.origin_translation))

        # Apply orientation
        frame_matrix = np.dot(frame_matrix, geometry.cartesian_to_homogeneous(geometry.rpy_matrix(*self.origin_orientation)))

        # Apply rotation matrix
        if self.has_rotation:
            frame_matrix = np.dot(frame_matrix, geometry.cartesian_to_homogeneous(geometry.axis_rotation_matrix(self.rotation, theta)))

        # Apply translation
        if self.has_translation:
            translation_vector = self.translation * mu
            frame_matrix = np.dot(frame_matrix, geometry.get_translation_matrix(translation_vector))

        return frame_matrix

```

[src/ikpy/link.py](https://github.com/Phylliade/ikpy/blob/95b289b1239fb644b1c2e9b799f5a7ec43d7bc37/src/ikpy/link.py#L231-L275) · [More projects using SymPy →](https://dashboard.exa.ai/playground/search?q=sympy%20GitHub%20projects)

**Quickstart**

```python
from sympy import Matrix

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

M.eigenvals()

```

From [matrices.html](https://docs.sympy.org/latest/modules/matrices/matrices.html)

### mpmath

[GitHub](https://github.com/mpmath/mpmath) · [PyPI](https://pypi.org/project/mpmath) · [Docs](https://mpmath.org/doc/current/basics.html)

Provides arbitrary-precision floating-point mathematical computation.

- Downloads / mo: 168.4M
- Stars: 1.2K
- Last release: 1.4.1
- License: BSD-3-Clause
- Capabilities: [From the mpmath docs](https://mpmath.org/doc/current/basics.html)

**Strengths**

- **Offers configurable working precision.** Set mp.dps to choose the working decimal precision.
- **Integrates functions along complex paths.** Use quad to evaluate integrals over a specified complex path.

**Watch out for**

- **Float inputs retain earlier rounding.** Use decimal strings when constructing high-precision decimal inputs.
- **Default precision changes persist.** Use workdps when a precision change should be temporary.

```sh
pip install mpmath==1.4.1
```

**Quickstart**

```python
from mpmath import mp
with mp.workdps(50):
    print(mp.sqrt(2))

```

From [basics.html](https://mpmath.org/doc/current/basics.html) · [Find projects using mpmath →](https://dashboard.exa.ai/playground/search?q=Python%20projects%20using%20mpmath%20for%20scalar%20geometry%20vector%20normalization%20filtering%20quadrature%20and%20arbitrary-precision%20conversion&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

### PyTorch

[GitHub](https://github.com/pytorch/pytorch) · [PyPI](https://pypi.org/project/torch) · [Docs](https://docs.pytorch.org/docs/2.15/linalg.html)

Computes with tensors and dynamic neural networks on GPUs.

- 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
- Capabilities: [From the PyTorch docs](https://docs.pytorch.org/docs/2.15/linalg.html)

```sh
pip install torch
```

**nerfstudio-project/nerfstudio** (12.2K stars)

[nerfstudio-project/nerfstudio](https://github.com/nerfstudio-project/nerfstudio) 

```python
def focus_of_attention(poses: Float[Tensor, "*num_poses 4 4"], initial_focus: Float[Tensor, "3"]) -> Float[Tensor, "3"]:
    """Compute the focus of attention of a set of cameras. Only cameras
    that have the focus of attention in front of them are considered.

     Args:
        poses: The poses to orient.
        initial_focus: The 3D point views to decide which cameras are initially activated.

    Returns:
        The 3D position of the focus of attention.
    """
    # References to the same method in third-party code:
    # https://github.com/google-research/multinerf/blob/1c8b1c552133cdb2de1c1f3c871b2813f6662265/internal/camera_utils.py#L145
    # https://github.com/bmild/nerf/blob/18b8aebda6700ed659cb27a0c348b737a5f6ab60/load_llff.py#L197
    active_directions = -poses[:, :3, 2:3]
    active_origins = poses[:, :3, 3:4]
    # initial value for testing if the focus_pt is in front or behind
    focus_pt = initial_focus
    # Prune cameras which have the current have the focus_pt behind them.
    active = torch.sum(active_directions.squeeze(-1) * (focus_pt - active_origins.squeeze(-1)), dim=-1) > 0
    done = False
    # We need at least two active cameras, else fallback on the previous solution.
    # This may be the "poses" solution if no cameras are active on first iteration, e.g.
    # they are in an outward-looking configuration.
    while torch.sum(active.int()) > 1 and not done:
        active_directions = active_directions[active]
        active_origins = active_origins[active]
        # https://en.wikipedia.org/wiki/Line–line_intersection#In_more_than_two_dimensions
        m = torch.eye(3) - active_directions * torch.transpose(active_directions, -2, -1)
        mt_m = torch.transpose(m, -2, -1) @ m
        focus_pt = torch.linalg.inv(mt_m.mean(0)) @ (mt_m @ active_origins).mean(0)[:, 0]
        active = torch.sum(active_directions.squeeze(-1) * (focus_pt - active_origins.squeeze(-1)), dim=-1) > 0
        if active.all():
            # the set of active cameras did not change, so we're done.
            done = True
    return focus_pt

```

[nerfstudio/cameras/camera_utils.py](https://github.com/nerfstudio-project/nerfstudio/blob/50e0e3c70c775e89333256213363badbf074f29d/nerfstudio/cameras/camera_utils.py#L514-L549) · [More projects using PyTorch →](https://dashboard.exa.ai/playground/search?q=torch%20GitHub%20projects)

**Quickstart**

```python
import torch

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

```

From [torch.linalg.solve.html](https://docs.pytorch.org/docs/2.15/generated/torch.linalg.solve.html)

### Dask

[GitHub](https://github.com/dask/dask) · [PyPI](https://pypi.org/project/dask) · [Docs](https://docs.dask.org/en/stable/array-api.html)

Runs PyData workloads in parallel with task scheduling.

- Downloads / mo: 31.6M
- Stars: 14.0K
- Last release: 2026.8.0
- License: BSD-3-Clause
- Capabilities: [From the Dask docs](https://docs.dask.org/en/stable/array-api.html)

```sh
pip install "dask[array]"
```

**dask/dask-ml** (951 stars)

[dask/dask-ml](https://github.com/dask/dask-ml) 

```python
def fit_transform(self, X, y=None):
    """Fit model to X and perform dimensionality reduction on X.

    Parameters
    ----------
    X : array-like, shape (n_samples, n_features)
        Training data.

    y : Ignored

    Returns
    -------
    X_new : array, shape (n_samples, n_components)
        Reduced version of X. This will always be a dense array, of the
        same type as the input array. If ``X`` was a ``dask.array``, then
        ``X_new`` will be a ``dask.array`` with the same chunks along the
        first dimension.
    """
    X = self._check_array(X)
    if self.algorithm not in {"tsqr", "randomized"}:
        raise ValueError(
            "`algorithm` must be 'tsqr' or 'randomized', not '{}'".format(
                self.algorithm
            )
        )
    if self.algorithm == "tsqr":
        u, s, v = da.linalg.svd(X)
        u = u[:, : self.n_components]
        s = s[: self.n_components]
        v = v[: self.n_components]
    else:
        u, s, v = da.linalg.svd_compressed(
            X, self.n_components, n_power_iter=self.n_iter, seed=self.random_state
        )
    if not DASK_2_26_0:
        u, v = svd_flip(u, v)

    X_transformed = u * s
    explained_var = X_transformed.var(axis=0)
    full_var = X.var(axis=0).sum()
    explained_variance_ratio = explained_var / full_var

    if self.compute:
        v, explained_var, explained_variance_ratio, s = compute(
            v, explained_var, explained_variance_ratio, s
        )
    self.components_ = v
    self.explained_variance_ = explained_var
    self.explained_variance_ratio_ = explained_variance_ratio
    self.singular_values_ = s
    self.n_features_in_ = X.shape[1]
    return X_transformed

```

[dask_ml/decomposition/truncated_svd.py](https://github.com/dask/dask-ml/blob/fcc8111ac686e086985902f2050b3b17464966dc/dask_ml/decomposition/truncated_svd.py#L157-L208) · [More projects using Dask →](https://dashboard.exa.ai/playground/search?q=dask%20GitHub%20projects)

**Quickstart**

```python
import dask.array as da

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

```

From [array-api.html](https://docs.dask.org/en/stable/array-api.html)

### NumExpr

[GitHub](https://github.com/pydata/numexpr) · [PyPI](https://pypi.org/project/numexpr) · [Docs](https://raw.githubusercontent.com/pydata/numexpr/3b5ddaad460a1cb65ca8f2c80c3bd6d6b173438a/doc/user_guide.rst)

Evaluates numerical expressions on NumPy arrays.

- Downloads / mo: 14.4M
- Stars: 2.5K
- Last release: 2.14.2
- License: MIT
- Capabilities: [From the NumExpr docs](https://raw.githubusercontent.com/pydata/numexpr/3b5ddaad460a1cb65ca8f2c80c3bd6d6b173438a/doc/user_guide.rst)

```sh
pip install numexpr==2.14.2 numpy==2.5.5
```

**pandas-dev/pandas** (49.6K stars)

[pandas-dev/pandas](https://github.com/pandas-dev/pandas) 

```python
def _evaluate(self):
    import numexpr as ne

    # convert the expression to a valid numexpr expression
    s = self.convert()

    env = self.expr.env
    scope = env.full_scope
    _check_ne_builtin_clash(self.expr)
    return normalize_numexpr_result(ne.evaluate(s, local_dict=scope))

```

[pandas/core/computation/engines.py](https://github.com/pandas-dev/pandas/blob/5a96bfa5f03224fb5dd0d895e5eb5f1beda23cf7/pandas/core/computation/engines.py#L115-L124) · [More projects using NumExpr →](https://dashboard.exa.ai/playground/search?q=numexpr%20GitHub%20projects)

**Quickstart**

```python
import numpy as np
import numexpr as ne
a = np.arange(10)
print(ne.evaluate("a**2 + 1", local_dict={"a": a}))

```

From [user_guide.rst](https://raw.githubusercontent.com/pydata/numexpr/3b5ddaad460a1cb65ca8f2c80c3bd6d6b173438a/doc/user_guide.rst)

### JAX

[GitHub](https://github.com/jax-ml/jax) · [PyPI](https://pypi.org/project/jax) · [Docs](https://docs.jax.dev/en/latest/jax.numpy.linalg.html)

Differentiates, compiles, and transforms NumPy code.

- Downloads / mo: 12.8M
- Stars: 36.6K
- Last release: 0.12.1
- License: Apache-2.0
- Capabilities: [From the JAX docs](https://docs.jax.dev/en/latest/jax.numpy.linalg.html)

```sh
pip install jax
```

**deepmodeling/jax-fem** (784 stars)

[deepmodeling/jax-fem](https://github.com/deepmodeling/jax-fem) 

```python
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

```

[jax_fem/solver.py](https://github.com/deepmodeling/jax-fem/blob/01d11bdb57aa76dcfe7189e0e77d067960c2a6ac/jax_fem/solver.py#L382-L387) · [More projects using JAX →](https://dashboard.exa.ai/playground/search?q=jax%20GitHub%20projects)

**Quickstart**

```python
import jax.numpy as jnp

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

```

From [jax.numpy.linalg.norm.html](https://docs.jax.dev/en/latest/_autosummary/jax.numpy.linalg.norm.html)

## FAQ

### Which Python math library should I use?

[NumPy](#numpy) suits numerical work on arrays and matrices. [SciPy](#scipy) adds integration, optimization, and other scientific algorithms on top of NumPy arrays. [SymPy](#sympy) suits exact symbolic math. [mpmath](#mpmath) suits arithmetic at arbitrary precision.

### What is NumPy?

[NumPy](#numpy) is the core package for array computing in Python, with broadcasting, elementwise functions, and linear algebra.

### What is SymPy?

[SymPy](#sympy) is a computer algebra system that keeps expressions exact and manipulates them symbolically. Its evalf method computes numerical approximations to a chosen number of digits.

### NumPy vs SciPy: what is the difference?

[NumPy](#numpy) supplies the array type and core numerical operations. [SciPy](#scipy) builds on those arrays with algorithms for integration, differential equations, optimization, and signal processing.

### What is JAX?

[JAX](#jax) runs NumPy-style array code with automatic differentiation and compilation on supported accelerators.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best Python math libraries math NumPy SciPy mpmath code examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
