Skip to main content
Albero Academy

Why NumPy

What NumPy is, why it exists, and why it underpins the entire Python data stack.

Foundations9 min

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.

loops vs vectorised
import numpy as np
# Pure Python — a slow loop
squares = [x * x for x in range(1_000_000)]
# NumPy — whole-array, no loop, much faster
a = 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

  1. 01NumPy is the foundation of the Python data stack — pandas, scikit-learn and ML libraries build on it.
  2. 02It gives Python fast, memory-efficient numerical arrays backed by optimised C.
  3. 03Whole-array (vectorised) operations replace slow Python loops — often 10–100× faster.
  4. 04Import it as np by convention.

Finished this chapter?

Mark it complete to track your progress through NumPy.