NumPy
NumPy is the array engine underneath Pandas, scikit-learn, PyTorch, and JAX. Learn vectorization, broadcasting, and the linear algebra you'll use every day.
- Chapter 01
Fundamentals
6 lessons - 01 Why NumPy Pure-Python loops are 100× slower than NumPy for numeric work. Here's why — and how to think in vectorized operations.
- 02 The ndarray Every NumPy object is an ndarray — shape, dtype, ndim, size, strides. Understand these attributes and array bugs stop being mysterious.
- 03 Array creation zeros, ones, arange, linspace, random — the constructors you'll reach for every day, and when to use which.
- 04 Dtypes deep dive int8 vs int64, float32 vs float64, and the silent overflow bug that ate someone's pixel data. Pick the right dtype.
- 05 Indexing & slicing Basic slices, multi-axis indexing, fancy indexing, and the views-vs-copies trap that mutates data behind your back.
- 06 Reshape, ravel, transpose reshape, transpose, swapaxes, newaxis, squeeze — moving data between shapes without copying.
- Chapter 02
Vectorization
4 lessons - 07 Broadcasting How NumPy combines arrays of different shapes — the rule that makes vectorization actually work.
- 08 Universal functions Element-wise operations that run in C, beat Python loops by 100×, and accept `out=` and `where=` for in-place magic.
- 09 Aggregations & axis sum, mean, std, percentile — and the mental model for `axis` that makes per-row vs per-column reductions obvious.
- 10 Boolean masks Comparison ops, mask combinators, np.where — the filter-and-modify toolkit that powers every Pandas query under the hood.
- Chapter 03
Linear Algebra
4 lessons - 11 dot, matmul, @ np.dot, np.matmul, and the @ operator — what they do, where they differ, and how to read the shape rules.
- 12 np.linalg toolbox solve, inv, det, norm, eig, svd, qr, pinv — the linear algebra toolbox you need for regression, PCA, and recommender systems.
- 13 einsum — one mental model A single mental model — repeated indices sum, free indices stay — that expresses matmul, transpose, trace, and batched ops in one line.
- 14 Random & reproducibility Use np.random.default_rng — not the old global API. Seeding, distributions, sampling, and the reproducibility rules every ML notebook needs.
- End of section 0 / 14 complete
Make it stick — pass every quiz.
Each lesson has a short quiz at the bottom. Passing the quiz is what marks the lesson complete and counts toward your certificate.
NumPy — frequently asked questions
Straight answers to the questions people ask most about numpy.
Why use NumPy instead of plain Python lists?
NumPy stores data in contiguous, typed arrays and runs operations in optimised C, so element-wise math on large arrays is often 10–100× faster than Python loops and uses far less memory. It's the foundation Pandas, scikit-learn, and PyTorch are built on.
What is broadcasting in NumPy?
Broadcasting is how NumPy applies an operation between arrays of different shapes without copying data — it virtually stretches the smaller array to match the larger one. For example, subtracting a 1D row of column means from a 2D matrix works per-column without a loop, as long as the trailing dimensions are compatible.
What does the axis argument mean in NumPy?
`axis` names the dimension the operation collapses along. For a 2D array, `axis=0` reduces down the rows (one result per column) and `axis=1` reduces across the columns (one result per row). The common mistake is reading 'axis=0' as 'rows' when it actually aggregates over them.
What's the difference between a NumPy view and a copy?
Basic slicing returns a view — a window into the same memory — so changing the slice changes the original array. Fancy indexing (with a list or boolean mask) returns a copy. Call `.copy()` when you need an independent array to avoid surprising in-place mutations.
Should I ever use a Python loop over a NumPy array?
Rarely. Prefer vectorised operations, broadcasting, and built-in functions, which run in C and are far faster. Reach for a loop only when the logic genuinely can't be vectorised, and even then consider tools like Numba.