Pythonnumpyv2.4.4
PythonBeginner-friendly

numpy

Fundamental package for array computing in Python

numpyarraylinear-algebrascientificmatrixscientific/engineering
The Problem

Python lists are general-purpose and slow for numerical work โ€” each element is a Python object with overhead, and there's no vectorised math. Before NumPy, scientific computing in Python meant writing slow loops or reaching for C extensions manually. NumPy solved this by providing a typed, contiguous array backed by optimised C and Fortran code.

Mental Model

Think of a NumPy ndarray as a typed, multi-dimensional grid of numbers stored contiguously in memory. Operations on the array run in compiled C โ€” adding two arrays of a million numbers is a single C loop, not a million Python function calls. The key insight is 'vectorise your thinking': replace loops with operations on whole arrays.

60-second start

Install numpy

pip install numpy
import numpy

Use it when

Use NumPy any time you're doing numerical computation: matrix math, statistics, signal processing, image data as pixel arrays, or feeding data into ML libraries. It's the foundation most scientific Python libraries (pandas, scipy, PyTorch) are built on.

Skip it when

NumPy is not for general-purpose data manipulation with mixed types or strings โ€” use pandas DataFrames there. For very large datasets that don't fit in RAM, look at Dask or CuPy (GPU arrays).

Alternatives
pandasBuilt on NumPy; adds labelled columns, mixed types, and data wrangling โ€” better for tabular data
polarsFaster DataFrame library written in Rust; good when you need speed but don't need NumPy's raw array API
torchPyTorch tensors mirror NumPy's API but run on GPU โ€” the natural upgrade for ML workloads

Ready to explore the full API?

See every class, function, and relationship in an interactive graph.