Languages
NumPy Cheat Sheet
Print-ready cheat sheet for NumPy, organized for fast lookup, study, and desk-side use
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.shape | Dimensions as tuple: `(3, 4)` |
a.ndim | Number of dimensions |
a.size | Total number of elements |
a.dtype | Data type: `float64`, `int32`, etc. |
Download the full cheat sheet for all sections, formatted for print
Download PDFDownloads
Choose the treatment that matches how you read
-
Recommended
Standard
B&W, ink-efficient. The default for laser printers and photocopies
Best for Printouts and desk-side reference
-
Color
Warm color accents for on-screen reading or color printers
Best for Screen reading or color printers
-
Reference Card
Maximum density, 4-column layout. Everything on one page
Best for Fast scanning and minimum paper use