Python
Python is widely used to explore machine learning. Here, you will write small programs, inspect their results, and build numerical experiments. Previous programming experience helps, but the opening chapters begin with the basics.
A program is a precise way to test an idea. Python gives us a compact way to write that test and see the result. Throughout this subject, the examples stay small enough to read, run, and change.
The first half develops everyday Python: values, decisions, loops, functions, collections, errors, files, and simple records. The second half turns to numerical work with NumPy, array calculations, plots, randomness, and a complete experiment.
Do not try to memorize every detail on the first pass. Predict what a short program will do, run it, compare the result with your prediction, and then change one thing. When an error appears, treat it as evidence about what the program expected.
Chapters
If Python is new to you, begin with Chapter 1 and follow the sequence. If you already use Python, begin with the first chapter whose examples are unfamiliar.
What programming and Python are, how to run a small program, and how to inspect its output and errors.
7 lessons23 exercisesChapter 2Names, Values, and TypesLearn how names refer to values, how expressions produce results, and how types determine which operations make sense.
6 lessons35 exercisesChapter 3Branches and LoopsChoose between actions with branches, repeat work with loops, maintain totals, and check loop boundaries.
6 lessons34 exercisesChapter 4FunctionsDefine readable Python functions, trace arguments and scope, add basic type hints, return results, use defaults, and check behavior with tests.
7 lessons40 exercisesChapter 5Collections and IterationChoose and use Python collections, iterate over values, select sequence ranges, transform data, and reason about mutation and copying.
7 lessons47 exercisesChapter 6Errors and DebuggingRead Python tracebacks, diagnose common exceptions, handle expected failures, test assumptions, and reduce bugs systematically.
8 lessons50 exercisesChapter 7Files, Paths, and ModulesLearn how Python programs read and write text files, build portable paths, manage project environments, reuse modules, define script entry points, and organize a small project.
7 lessons47 exercisesChapter 8Objects, Records, and Type HintsOrganize related values with attributes, classes, and dataclasses, then document and statically check function interfaces.
6 lessons44 exercisesChapter 9NumPy ArraysCreate NumPy arrays and reason about their shape, data type, axes, indexing, views, copies, and common errors.
7 lessons45 exercisesChapter 10Array ComputationCompute with whole NumPy arrays using elementwise operations, Boolean masks, broadcasting, centering, vectorization, and matrix products while tracking values, axes, dtypes, and shapes.
7 lessons48 exercisesChapter 11Plotting and InspectionUse Matplotlib to inspect numerical data, distributions, arrays, loss surfaces, and computational mistakes.
9 lessons55 exercisesChapter 12Randomness and ReproducibilityGenerate, sample, shuffle, and split data while recording enough evidence to reproduce and compare randomized computations.
7 lessons45 exercisesChapter 13A Small Numerical ProjectBuild a complete Python project that generates noisy data, fits a line, inspects the evidence, and records a reproducible result.
7 lessons45 exercises