NumPy, by Running It

Arrays instead of loops - the shapes, the broadcasting rules, and the views that catch everyone, each one runnable on the page.

20 modules Free, no login Updated 15 October 2026

About this track

A Python list holds pointers to objects scattered across memory. A NumPy array holds numbers, of one type, laid out end to end. Almost everything that makes NumPy fast, and everything that makes it surprising, follows from that one difference.

This track works up from creating an array to broadcasting, views, aggregation along an axis, and the linear algebra underneath every machine learning library. Every idea arrives as a small program you can run and edit here, because the fastest way to settle what a shape will do is to print it.

Every example runs in the browser against the real library, and several are written so the output contradicts the guess most people would make - that a slice is a copy, or that axis=0 means along the rows. Being wrong on the page and seeing it immediately is the point.

What you will be able to do

How the track is ordered

Arrays come first, because the dtype and the shape decide almost everything that follows. Then indexing and slicing, which is where views appear, and vectorised arithmetic, which is the reason to use the library at all. Broadcasting, masking and fancy indexing build on those three. Aggregation along an axis comes next, then the structural operations - stacking, transposing, sorting - and finally the linear algebra that sits under every machine learning library, plus the performance and file-format material you need once the arrays get large.

Where this leads

NumPy is the layer under pandas, scikit-learn, PyTorch and matplotlib, so the shapes and dtypes here reappear in all of them. The pandas track adds labels and mixed types to the same arrays; the matplotlib track draws them.

All 20 modules, in teaching order

  1. 01What NumPy Is ForSee why NumPy stores numbers in one contiguous block of typed memory and how that layout makes array operations orders of magnitude faster.
  2. 02Creating ArraysCreate NumPy arrays with array, zeros, arange, linspace and random. See which constructor fits each situation and what dtype each one picks.
  3. 03DtypesSet and inspect the dtype of a NumPy array. See how integer overflow, float precision and type promotion affect calculations without warning.
  4. 04Shape and ReshapeReshape a NumPy array without copying data. Use reshape, ravel and newaxis to rearrange dimensions while the underlying memory stays put.
  5. 05Indexing and SlicingSlice rows, columns and blocks from a NumPy array. Learn the one slicing behaviour that differs from Python lists and why it matters.
  6. 06Vectorised ArithmeticReplace Python loops with NumPy element-wise operations. See the speedup on arrays of every size and avoid the two patterns that lose it.
  7. 07BroadcastingAdd a row vector to a column vector and watch NumPy expand the shapes automatically. Learn the two rules that decide when broadcasting works.
  8. 08Boolean MaskingWrite a comparison on a NumPy array and use the resulting boolean array as an index. Filter, count and replace elements without any loop.
  9. 09Fancy IndexingIndex a NumPy array with a list of positions to reorder, repeat or select scattered elements. See how the index shape decides the output shape.
  10. 10Aggregations and axisRun sum, mean and max on a NumPy array and change the axis argument. See how one parameter decides whether the result is a row, column or scalar.
  11. 11Views versus CopiesLearn which NumPy operations return a view and which return a copy. Modify a slice and see the change appear, or not, in the original array.
  12. 12Stacking and SplittingJoin NumPy arrays with vstack, hstack and concatenate. Split them with array_split and see when to stack along a new axis instead.
  13. 13Transpose and Moving AxesTranspose a NumPy array and reorder its axes with swapaxes and moveaxis. See how the operation changes strides without copying any data.
  14. 14Sorting and SearchingSort a NumPy array, get sorted indices with argsort and find insertion points with searchsorted. See why argsort is usually the more useful call.
  15. 15Unique Values and Set OperationsFind unique values, counts and set intersections in a NumPy array. Rebuild the original from the unique values and an inverse index.
  16. 16Random NumbersGenerate random integers, floats and samples with NumPy's Generator API. Set a seed for reproducible results and avoid the legacy functions.
  17. 17Linear AlgebraMultiply matrices, solve linear systems and compute eigenvalues with NumPy. See why you should call solve instead of computing the inverse.
  18. 18NaN and Missing DataWork with NaN values in NumPy. Learn why NaN breaks comparisons and aggregations, and switch to nanmean and nansum to handle it correctly.
  19. 19Performance and MemoryProfile a NumPy workflow to find where time and memory go. Replace Python loops, cut unnecessary copies and pick smaller dtypes.
  20. 20Saving and Loading ArraysSave and load NumPy arrays with npy, npz and text formats. Compare speed, file size and portability to choose the right format for your data.

Other tracks