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.
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
- Predict an operation's result shape from the shapes going in, rather than running it to find out.
- Apply the broadcasting rules deliberately, including the cases where they raise.
- Tell a view from a copy, and know which operations give you which.
- Read axis= as the axis that disappears, and get the same answer in any number of dimensions.
- Choose a dtype that fits the data, and recognise the silent overflow when one does not.
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
- 01What NumPy Is For
- 02Creating Arrays
- 03Dtypes
- 04Shape and Reshape
- 05Indexing and Slicing
- 06Vectorised Arithmetic
- 07Broadcasting
- 08Boolean Masking
- 09Fancy Indexing
- 10Aggregations and axis
- 11Views versus Copies
- 12Stacking and Splitting
- 13Transpose and Moving Axes
- 14Sorting and Searching
- 15Unique Values and Set Operations
- 16Random Numbers
- 17Linear Algebra
- 18NaN and Missing Data
- 19Performance and Memory
- 20Saving and Loading Arrays