datarekha
Section 3 chapters · 14 of 14 lessons

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.

0 / 14 lessons
The NumPy journey 0 / 14 completed
  1. Chapter 01

    Fundamentals

    6 lessons
  2. 01 Why NumPy Pure-Python loops are 100× slower than NumPy for numeric work. Here's why — and how to think in vectorized operations. Beginner5 min
  3. 02 The ndarray Every NumPy object is an ndarray — shape, dtype, ndim, size, strides. Understand these attributes and array bugs stop being mysterious. Beginner7 min
  4. 03 Array creation zeros, ones, arange, linspace, random — the constructors you'll reach for every day, and when to use which. Beginner6 min
  5. 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. Intermediate7 min
  6. 05 Indexing & slicing Basic slices, multi-axis indexing, fancy indexing, and the views-vs-copies trap that mutates data behind your back. Beginner8 min
  7. 06 Reshape, ravel, transpose reshape, transpose, swapaxes, newaxis, squeeze — moving data between shapes without copying. Intermediate6 min
  8. Chapter 02

    Vectorization

    4 lessons
  9. 07 Broadcasting How NumPy combines arrays of different shapes — the rule that makes vectorization actually work. Intermediate9 min
  10. 08 Universal functions Element-wise operations that run in C, beat Python loops by 100×, and accept `out=` and `where=` for in-place magic. Intermediate6 min
  11. 09 Aggregations & axis sum, mean, std, percentile — and the mental model for `axis` that makes per-row vs per-column reductions obvious. Beginner6 min
  12. 10 Boolean masks Comparison ops, mask combinators, np.where — the filter-and-modify toolkit that powers every Pandas query under the hood. Intermediate6 min
  13. Chapter 03

    Linear Algebra

    4 lessons
  14. 11 dot, matmul, @ np.dot, np.matmul, and the @ operator — what they do, where they differ, and how to read the shape rules. Intermediate6 min
  15. 12 np.linalg toolbox solve, inv, det, norm, eig, svd, qr, pinv — the linear algebra toolbox you need for regression, PCA, and recommender systems. Advanced8 min
  16. 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. Advanced9 min
  17. 14 Random & reproducibility Use np.random.default_rng — not the old global API. Seeding, distributions, sampling, and the reproducibility rules every ML notebook needs. Intermediate6 min
  18. 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.

    Section complete 14 / 14 lessons

    Nice work — you finished NumPy.

    Certificates are earned per learning path, not per section. Here's where this section takes you:

FAQCommon questions

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.

Skip to content