You have covered the core of NumPy. This page recaps the essentials on one screen, gives you a practice exercise that uses most of the course, and points you to what to learn next.
Cheat sheet
Task | Code |
|---|---|
Create an array |
|
Ranges of numbers |
|
Shape and size |
|
Change the type |
|
Reshape |
|
Index and slice |
|
Filter |
|
Join and split |
|
Sort and search |
|
Math |
|
Statistics |
|
Random numbers |
|
Linear algebra |
|
Practice: put it all together
Seven days of temperatures for three cities. Try to predict each line of output before you read it:
Example
import numpy as np
rng = np.random.default_rng(7)
temps = rng.integers(20, 41, size=(7, 3)) # 7 days x 3 cities
print(temps)
print("Average per city:", temps.mean(axis=0).round(1))
print("Hot days (35+) per city:", (temps >= 35).sum(axis=0))
print("Hottest day for each city:", temps.argmax(axis=0))
Output
[[39 33 34]
[38 32 36]
[37 24 21]
[26 25 38]
[39 20 30]
[37 22 36]
[22 29 37]]
Average per city: [34. 26.4 33.1]
Hot days (35+) per city: [5 0 4]
Hottest day for each city: [0 0 3]
Go deeper
The Complete NumPy Guide on this site goes much further, with performance tips, real-world pipelines and interview questions:
What to learn next
pandas — tables with labelled rows and columns, built on NumPy. See the pandas tutorials.
Matplotlib — turn NumPy arrays into charts.
scikit-learn — machine learning models that take NumPy arrays as input.