Languages

NumPy Cheat Sheet

Print-ready cheat sheet for NumPy, organized for fast lookup, study, and desk-side use

Source
NumPy Documentation (numpy.org)
License
MIT
Updated
2026-03-27

Sample

What's in this cheat sheet

  • Array Creation
  • Indexing & Slicing
  • Array Operations
  • Math Functions
  • Linear Algebra
  • Random
  • Reshaping
  • Broadcasting
  • File I/O
  • Common Patterns

From Lists

import numpy as np
a = np.array([1, 2, 3])        # 1D
b = np.array([[1, 2], [3, 4]])  # 2D

Built-in Constructors

np.zeros((2, 3))     # 2x3 of zeros
np.ones((3, 3))      # 3x3 of ones
np.eye(4)            # 4x4 identity matrix
np.arange(0, 10, 2)  # [0, 2, 4, 6, 8]
np.linspace(0, 1, 5) # 5 evenly spaced

Array Properties

a.shapeDimensions as tuple: `(3, 4)`
a.ndimNumber of dimensions
a.sizeTotal number of elements
a.dtypeData type: `float64`, `int32`, etc.

Download the full cheat sheet for all sections, formatted for print

Download PDF

Downloads

Choose the treatment that matches how you read