NumPy Cheat Sheet
On This Page
Bonus Chapter: NumPy Cheat Sheet
Quick reference for the NumPy operations covered in Module 13 — the numerical backbone of Python data analytics.
CS3.1 Creating Arrays
| Command | Purpose |
|---|
| np.array([1,2,3]) | Create array from a list |
| np.zeros(5) | Array of 5 zeros |
| np.ones((2,3)) | 2x3 array of ones |
| np.arange(0,10,2) | Range-like array |
| np.linspace(0,1,5) | 5 evenly spaced values between 0-1 |
CS3.2 Indexing & Slicing
arr[0] # first element
arr[-1] # last element
arr[1:4] # slice
matrix[0, 2] # row 0, column 2
matrix[1, :] # entire row 1
matrix[:, 0] # entire column 0
CS3.3 Math & Broadcasting
a + b, a - b, a * b, a / b # element-wise math
arr + 5 # broadcasting - adds 5 to every element
arr * 1.1 # scale every element by 10%
CS3.4 Aggregation Functions
| Function | Purpose |
|---|
| np.sum(arr) | Total of all elements |
| np.mean(arr) | Average |
| np.median(arr) | Median |
| np.std(arr) | Standard deviation |
| np.max(arr) / np.min(arr) | Largest / smallest value |
| arr.sum(axis=0/1) | Sum along rows/columns |
CS3.5 Reshaping
data = np.arange(1, 13)
reshaped = data.reshape(3, 4) # 3 rows, 4 columns
flattened = reshaped.flatten() # back to 1D
ℹ Reminder
Full explanations and worked examples for every command on this sheet are in Module 13 of the main training manual.