NumPy (Numerical Python) is the foundation of scientific computing in Python. Pandas, scikit-learn, SciPy, TensorFlow and PyTorch are all built on its core object — the ndarray. Learn NumPy and you've learned the substrate the whole data ecosystem stands on.
The problem it solves
A Python list can hold anything, which makes it flexible but slow for numbers: each element is a full Python object with overhead, and looping over millions of them in pure Python is painfully slow. NumPy stores numbers in one contiguous block of memory and runs operations in optimised C — often 10–100× faster, in a fraction of the code.
import numpy as np# Pure Python — a slow loopsquares = [x * x for x in range(1_000_000)]# NumPy — whole-array, no loop, much fastera = np.arange(1_000_000)squares = a ** 2
The np convention
The near-universal convention is import numpy as np. You'll see np. everywhere — follow it so your code reads like everyone else's.
When to use NumPy
- Numerical data: measurements, pixels, signals, features, weights.
- Whole-array maths ("add 18% to every price", "normalise each column").
- As the engine under pandas/scikit-learn — even when you don't call it directly.
Key takeaways
- 01NumPy is the foundation of the Python data stack — pandas, scikit-learn and ML libraries build on it.
- 02It gives Python fast, memory-efficient numerical arrays backed by optimised C.
- 03Whole-array (vectorised) operations replace slow Python loops — often 10–100× faster.
- 04Import it as np by convention.
