NumPy

This content was generated with the assistance of AI and should be verified against the official documentation before being relied on in production.

NumPy is the array library that the rest of the Python scientific stack builds on: pandas, SciPy, scikit-learn and Matplotlib all store and exchange their numbers as NumPy arrays. This sub-section is a practical reference to the library, from the first ndarray to memory layout, threading and the C API. It belongs to the Data Science section, which also holds the pandas and scikit-learn sub-sections, and a condensed summary of the commands most used day to day is on the NumPy part of the cheat sheet.

Version baseline

Every page targets NumPy 2.5, and the facts were checked against the official documentation in October 2026. Examples target Python 3.13 or 3.14 and were run on Python 3.13. NumPy 2.5 itself needs Python 3.12 or later. Code written for NumPy 1.x often needs small changes; the Migrating to NumPy 2.x page lists them, and What’s New in NumPy 2.1 to 2.5 follows the releases one by one.

How to read this sub-section

Concept-to-page map

Getting started

Page Concept

NumPy Installation and Versions

Installing with pip, uv or conda, checking the version, release cadence and supported Python versions.

The Absolute Basics of NumPy

A first tour of the ndarray: attributes, slicing, reshaping, arithmetic, aggregation and saving.

What’s New in NumPy 2.1 to 2.5

Release-by-release changes, deprecations and the upcoming 2.6.

Migrating to NumPy 2.x

Renamed and removed names, behaviour changes and how to adapt older code.

Creating arrays and choosing types

Page Concept

NumPy Array Creation

array, zeros, full, the _like variants, eye, fromiter and related constructors.

NumPy Ranges and Grids

arange, linspace, logspace, meshgrid and mgrid.

Data Types

The dtype system, sizes, casting and character codes.

Type Promotion (NEP 50)

How operands of different types are combined under the NumPy 2 rules.

Strings, Bytes and StringDType

Text in arrays, fixed-width strings and the variable-width StringDType.

Dates and Times with datetime64

Dates, timestamps, units and time deltas.

Structured Arrays

Record-like dtypes with named fields.

Masked Arrays

Arrays with missing or invalid entries.

Selecting, reshaping and combining

Page Concept

Basic Indexing and Slicing

Integer indices, slices, Ellipsis and newaxis.

Advanced and Boolean Indexing

Integer-array and boolean selection, assignment and result shapes.

Copies and Views

When an operation shares memory and when it copies.

Reshaping, Stacking & Splitting

reshape, concatenation, stacking and splitting.

Sorting, Searching & Counting

Sorting, searchsorted, argmax, where and counting.

Set Operations

unique, membership tests, union, intersection and difference.

Computing

Page Concept

Universal Functions (ufuncs)

Element-wise functions, out, where, reductions and accumulation.

Broadcasting

The shape-matching rules for operations on arrays of different shapes.

Reductions and Axis Semantics

sum, mean, max and friends, axis and keepdims.

Statistics & Histograms

Descriptive statistics, correlation and histograms.

Linear Algebra

Matrix products, decompositions, solvers and the linalg module.

Discrete Fourier Transforms

The numpy.fft module and frequency ordering.

Polynomials

The numpy.polynomial package, fitting and roots.

Floating-Point Errors and errstate

Overflow, underflow, invalid values and how to control the warnings.

Random numbers

Page Concept

Random Numbers with Generator

default_rng, distributions, sampling and shuffling.

Seeding, Reproducibility & Parallel Streams

Seeds, SeedSequence, spawning independent streams.

Input, output and display

Page Concept

Reading & Writing Files

save, load, text files and binary formats.

Printing Arrays

Print options, formatting and string conversion.

Internals, performance and interoperability

Page Concept

Memory Layout and Strides

C and Fortran order, strides and contiguity.

Threads, Free-Threading and Performance

Thread safety, free-threaded builds and speed.

Interoperability: Protocols and DLPack

Array protocols, __array_function__ and DLPack exchange.

The Array API Standard

Writing code that runs on several array libraries.

Static Typing with numpy.typing

Type annotations for arrays and dtypes.

C-API, Cython and F2PY

Extending NumPy with compiled code.

The Statistics & Histograms page covers the array-level functions, while Statistics Fundamentals explains the underlying ideas. The pandas sub-section builds on arrays through labelled data structures, and the scikit-learn sub-section expects NumPy arrays as its input format.

NumPy sources

Bibliography

All official links were opened on 2026-10-30.

NumPy and Python

Open references

Books

Books are linked to the publisher’s page. They were used only to decide which topics to cover, and no text or figure is reproduced.