← Back to courses

Course

NumPy - Numerical Computing with Python

76 lessons across 10 modules

Beginner to intermediate, assuming Core Python - the first step from Python towards data science and machine learning. Arrays, indexing, vectorised operations, statistics, reshaping and broadcasting, copies and views, and linear algebra, then NumPy with Pandas and scikit-learn - ending in four projects. The road is laid out in full; lessons are being written one at a time.

Course10 modules76 lessonsEach heading below is a module (one topic). Each card under it is a lesson. Start with Module 1.
Solid: ready (0)Dashed: coming soon (76)
Module 1 of 105 lessonsComing soon

NumPy Fundamentals

What NumPy is, and the array at the centre of it

Prerequisite: Core Python →

What is NumPy?

1

Fast, typed arrays for Python - the foundation of the data science stack.

A sum over a million numbers, as a list and as an array

Lesson 1planned

Installing and Importing NumPy

2

Installing with pip, importing as np, and checking the version.

import numpy as np, and why every example uses np

Lesson 2planned

NumPy Arrays

3

The ndarray - one data type, fixed size, stored contiguously.

A list turned into an array, and what changed

Lesson 3planned

Array Dimensions

4

From a single value to 0-D, 1-D, 2-D, and 3-D arrays.

A number, a row, a table, and a stack of tables

Lesson 4planned

Array Attributes

5

ndim, shape, size, dtype, itemsize, and nbytes.

Working out an array memory use from its attributes

Lesson 5planned
Module 2 of 108 lessonsComing soon

Creating NumPy Arrays

Every common way to make an array to start from

Creating Arrays from Lists and Tuples

6

np.array, and the dtype NumPy infers from the input.

A list mixing ints and floats becoming an all-float array

Lesson 6planned

zeros() and ones()

7

Arrays filled with zeros or ones, in any shape and dtype.

A 3 by 4 grid of zeros to fill in later

Lesson 7planned

full() and empty()

8

A constant fill, and uninitialised memory you must overwrite.

empty() returning leftover garbage values

Lesson 8planned

arange()

9

Evenly spaced values by step, with the stop excluded.

np.arange(0, 10, 2) and a float step that surprises

Lesson 9planned

linspace()

10

A fixed number of evenly spaced values, stop included.

Five points from 0 to 100, exactly

Lesson 10planned

Identity and Diagonal Arrays

11

eye(), identity(), and diag() for building and reading diagonals.

An identity matrix, and pulling a diagonal out of a grid

Lesson 11planned

Random Arrays

12

rand, randn, randint, uniform, and choice - and their distributions.

Uniform against normal noise, plotted side by side

Lesson 12planned

Random Seeds

13

Reproducible randomness, and the newer default_rng Generator API.

The same random numbers on every run, for a test

Lesson 13planned
Module 3 of 108 lessonsComing soon

Array Indexing and Slicing

Reaching into arrays, from one element to a filtered selection

Indexing 1-D Arrays

14

Zero-based positions, exactly as with Python lists.

The first and third element of a price array

Lesson 14planned

Negative Indexing

15

Counting back from the end.

The last three readings without knowing the length

Lesson 15planned

Slicing Arrays

16

start, stop, step - and a slice being a view, not a copy.

Changing a slice and finding the original changed too

Lesson 16planned

Indexing 2-D Arrays

17

arr[row, col] in one bracket, rather than arr[row][col].

One cell of a table of student marks

Lesson 17planned

Slicing 2-D Arrays

18

Selecting whole rows, whole columns, and sub-grids.

Every student marks in one subject, as a column

Lesson 18planned

Indexing 3-D Arrays

19

Three indices, and keeping track of which axis is which.

One pixel channel from an image array

Lesson 19planned

Boolean Indexing

20

Selecting elements with a mask of True and False.

Every mark above 50, in one expression

Lesson 20planned

Fancy Indexing

21

Selecting by a list of positions - and always getting a copy.

The first, fourth, and sixth rows, in any order you choose

Lesson 21planned
Module 4 of 107 lessonsComing soon

Array Operations

Arithmetic and functions applied to every element at once

Arithmetic Operations

22

Operators applied element by element, with no loop.

Adding tax to a whole price list in one line

Lesson 22planned

Operations Between Arrays

23

Combining two arrays element by element, and mismatched shapes.

Quantity times price for every product at once

Lesson 23planned

Comparison Operations

24

Comparisons that return an array of booleans.

A pass-or-fail mask built from marks

Lesson 24planned

Logical Operations

25

logical_and, logical_or, logical_not - and & with brackets.

A missing bracket around a comparison raising an error

Lesson 25planned

Mathematical Functions

26

sqrt, square, abs, power, exp, and log as universal functions.

A log of zero producing -inf and a warning

Lesson 26planned

Trigonometric Functions

27

sin, cos, and tan, working in radians.

np.sin(90) that should have been np.sin(np.pi / 2)

Lesson 27planned

Rounding Functions

28

round, floor, ceil, and trunc - and round-half-to-even.

np.round(2.5) returning 2.0

Lesson 28planned
Module 5 of 108 lessonsComing soon

Aggregation and Statistics

Summarising an array into the numbers that matter

Sum and Product

29

Totals and products over a whole array.

Monthly revenue as one sum

Lesson 29planned

Minimum and Maximum

30

The smallest and largest values.

The lowest and highest temperature of the week

Lesson 30planned

Mean, Median and Standard Deviation

31

Centre and spread - and the ddof setting that changes std.

A NumPy std that disagrees with Pandas until ddof is set

Lesson 31planned

Variance

32

Spread in squared units, and how it relates to std.

Two datasets with the same mean and very different variance

Lesson 32planned

Percentiles and Quantiles

33

The value below which a given share of the data falls.

The 90th percentile response time

Lesson 33planned

argmin() and argmax()

34

The position of the extreme, not its value.

Which student scored highest, not what they scored

Lesson 34planned

Aggregation Along an Axis

35

axis=0 down the columns, axis=1 across the rows.

An average per subject and an average per student from one table

Lesson 35planned

Handling NaN Values

36

isnan, and the nan-aware functions that skip missing data.

One NaN turning a whole mean into NaN

Lesson 36planned
Module 6 of 108 lessonsComing soon

Shape, Reshaping and Broadcasting

Changing an array shape, and operating on different shapes

Understanding Array Shape

37

Reasoning about axes - the skill reshaping and broadcasting both rely on.

Reading (32, 28, 28) as 32 images of 28 by 28 pixels

Lesson 37planned

reshape()

38

The same data in a new shape - the total size must match.

Six values as 2 by 3, and -1 letting NumPy work one side out

Lesson 38planned

Flattening Arrays

39

flatten always copies; ravel returns a view when it can.

Editing a raveled array and changing the original

Lesson 39planned

Transpose

40

Swapping axes with .T and np.transpose.

Rows of students turned into rows of subjects

Lesson 40planned

Adding and Removing Dimensions

41

expand_dims and squeeze, for shapes an API insists on.

One sample reshaped into a batch of one for a model

Lesson 41planned

Broadcasting Fundamentals

42

Operating on different shapes without copying data.

arr + 10 stretching the 10 across every element

Lesson 42planned

Broadcasting Rules

43

Compare shapes from the right; sizes must match or be 1.

A (3, 1) and a (4,) combining into a (3, 4)

Lesson 43planned

Practical Broadcasting Examples

44

Centring columns and pairwise differences, without loops.

Subtracting each column mean from every row in one line

Lesson 44planned
Module 7 of 107 lessonsComing soon

Combining and Manipulating Arrays

Joining, splitting, sorting, and searching

Concatenating Arrays

45

Joining arrays along an existing axis.

Two months of data combined into one array

Lesson 45planned

Vertical and Horizontal Stacking

46

vstack adds rows, hstack adds columns.

A new feature column added beside a dataset

Lesson 46planned

Splitting Arrays

47

split needs equal parts; array_split does not.

A dataset split into training and test portions

Lesson 47planned

Adding and Removing Elements

48

append, insert, and delete - each returning a brand new array.

np.append in a loop, and why it grows slowly

Lesson 48planned

Sorting Arrays

49

np.sort returns a copy; arr.sort sorts in place.

Sorting marks, and argsort to keep track of who scored them

Lesson 49planned

Searching Arrays

50

where to find or replace by condition; searchsorted for sorted data.

Negative values replaced with zero in one call

Lesson 50planned

Unique Values

51

Distinct values, and counting each one.

How many students got each grade

Lesson 51planned
Module 8 of 109 lessonsComing soon

Advanced NumPy

Memory, types, and why NumPy is fast

Copy vs View

52

When two arrays share memory, and how to tell.

A bug caused by editing what turned out to be a view

Lesson 52planned

Data Types

53

int32, int64, float32, float64, bool, and complex.

An int8 counter that overflowed without any error

Lesson 53planned

Type Conversion

54

astype, and the precision lost when narrowing.

Floats cast to integers and silently truncated

Lesson 54planned

Structured Arrays

55

Named, mixed-type fields in one array.

Names and scores stored in a single structured array

Lesson 55planned

Memory Layout

56

C-order against F-order, and contiguous memory.

The same sum faster along one axis than the other

Lesson 56planned

Vectorization

57

Replacing Python loops with whole-array operations.

A loop doubling every number, then numbers * 2

Lesson 57planned

Vectorized Functions

58

np.vectorize - convenient syntax, but still a loop underneath.

np.vectorize timed against a true array expression

Lesson 58planned

Performance: Python Lists vs NumPy

59

Measuring the gap honestly, including where lists win.

Ten elements where a list is faster, a million where it is not

Lesson 59planned

Memory-Efficient NumPy Operations

60

In-place operations, smaller dtypes, and avoiding temporary arrays.

A calculation that ran out of memory until it used out=

Lesson 60planned
Module 9 of 1012 lessonsComing soon

NumPy for Data Science and Machine Learning

Where arrays meet real datasets and models

Next: the Pandas course →

NumPy for Data Analysis

61

Loading, cleaning, and summarising a dataset with arrays alone.

Quick statistics on a dataset before reaching for Pandas

Lesson 61planned

NumPy for Feature Data

62

Rows as samples and columns as features.

Age and salary for three people as a 3 by 2 array

Lesson 62planned

NumPy for Machine Learning

63

Features, labels, the feature matrix X, and the target array y.

Splitting a dataset into X and y

Lesson 63planned

Normalization with NumPy

64

Scaling each feature to a 0 to 1 range.

Salary and age brought onto the same scale

Lesson 64planned

Standardization with NumPy

65

Zero mean and unit variance per feature.

Z-scores for every column in one broadcast expression

Lesson 65planned

Distance Calculations

66

Euclidean and Manhattan distance between points.

The nearest neighbour to one point, without a loop

Lesson 66planned

Matrix Operations

67

np.dot for dot products, and how it behaves in higher dimensions.

A weighted score as the dot product of weights and marks

Lesson 67planned

Matrix Multiplication

68

The @ operator, and the shapes that are allowed to multiply.

A (3, 2) @ (2, 4) giving a (3, 4)

Lesson 68planned

Linear Algebra

69

np.linalg - inverse, determinant, eigenvalues, and solving equations.

A system of equations solved with linalg.solve, not the inverse

Lesson 69planned

NumPy with CSV Data

70

loadtxt, genfromtxt, and savetxt - and their limits.

A CSV with a missing value that loadtxt cannot read

Lesson 70planned

NumPy with Pandas

71

A DataFrame column is a NumPy array underneath.

Moving between a DataFrame and an array, and back

Lesson 71planned

NumPy with Scikit-learn

72

How arrays flow through fit, transform, and predict.

A feature matrix passed into a model and predictions returned

Lesson 72planned
Module 10 of 104 lessonsComing soon

NumPy Projects and Practice

Four projects, from student marks to an ML-ready dataset

Project 1 - Student Marks Analyzer

73

Averages, extremes, subject averages, ranking, pass rates, and percentiles.

A full report card computed from one array of marks

Lesson 73planned

Project 2 - Sales Data Analyzer

74

Load, clean, aggregate, and summarise sales into business insights.

The best and worst months, and the products behind them

Lesson 74planned

Project 3 - Image Data Processing

75

An image as an array - brightness, cropping, grayscale, and transforms.

A colour photo turned grayscale with one weighted sum

Lesson 75planned

Final Project - ML Dataset Preprocessor

76

Missing values, outliers, normalisation, and standardisation into a feature matrix.

A raw dataset turned into one ready for a model

Lesson 76planned