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.
NumPy Fundamentals
What NumPy is, and the array at the centre of it
Prerequisite: Core Python →What is NumPy?
1Fast, typed arrays for Python - the foundation of the data science stack.
A sum over a million numbers, as a list and as an array
Installing and Importing NumPy
2Installing with pip, importing as np, and checking the version.
import numpy as np, and why every example uses np
NumPy Arrays
3The ndarray - one data type, fixed size, stored contiguously.
A list turned into an array, and what changed
Array Dimensions
4From 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
Array Attributes
5ndim, shape, size, dtype, itemsize, and nbytes.
Working out an array memory use from its attributes
Creating NumPy Arrays
Every common way to make an array to start from
Creating Arrays from Lists and Tuples
6np.array, and the dtype NumPy infers from the input.
A list mixing ints and floats becoming an all-float array
zeros() and ones()
7Arrays filled with zeros or ones, in any shape and dtype.
A 3 by 4 grid of zeros to fill in later
full() and empty()
8A constant fill, and uninitialised memory you must overwrite.
empty() returning leftover garbage values
arange()
9Evenly spaced values by step, with the stop excluded.
np.arange(0, 10, 2) and a float step that surprises
linspace()
10A fixed number of evenly spaced values, stop included.
Five points from 0 to 100, exactly
Identity and Diagonal Arrays
11eye(), identity(), and diag() for building and reading diagonals.
An identity matrix, and pulling a diagonal out of a grid
Random Arrays
12rand, randn, randint, uniform, and choice - and their distributions.
Uniform against normal noise, plotted side by side
Random Seeds
13Reproducible randomness, and the newer default_rng Generator API.
The same random numbers on every run, for a test
Array Indexing and Slicing
Reaching into arrays, from one element to a filtered selection
Indexing 1-D Arrays
14Zero-based positions, exactly as with Python lists.
The first and third element of a price array
Negative Indexing
15Counting back from the end.
The last three readings without knowing the length
Slicing Arrays
16start, stop, step - and a slice being a view, not a copy.
Changing a slice and finding the original changed too
Indexing 2-D Arrays
17arr[row, col] in one bracket, rather than arr[row][col].
One cell of a table of student marks
Slicing 2-D Arrays
18Selecting whole rows, whole columns, and sub-grids.
Every student marks in one subject, as a column
Indexing 3-D Arrays
19Three indices, and keeping track of which axis is which.
One pixel channel from an image array
Boolean Indexing
20Selecting elements with a mask of True and False.
Every mark above 50, in one expression
Fancy Indexing
21Selecting by a list of positions - and always getting a copy.
The first, fourth, and sixth rows, in any order you choose
Array Operations
Arithmetic and functions applied to every element at once
Arithmetic Operations
22Operators applied element by element, with no loop.
Adding tax to a whole price list in one line
Operations Between Arrays
23Combining two arrays element by element, and mismatched shapes.
Quantity times price for every product at once
Comparison Operations
24Comparisons that return an array of booleans.
A pass-or-fail mask built from marks
Logical Operations
25logical_and, logical_or, logical_not - and & with brackets.
A missing bracket around a comparison raising an error
Mathematical Functions
26sqrt, square, abs, power, exp, and log as universal functions.
A log of zero producing -inf and a warning
Trigonometric Functions
27sin, cos, and tan, working in radians.
np.sin(90) that should have been np.sin(np.pi / 2)
Rounding Functions
28round, floor, ceil, and trunc - and round-half-to-even.
np.round(2.5) returning 2.0
Aggregation and Statistics
Summarising an array into the numbers that matter
Sum and Product
29Totals and products over a whole array.
Monthly revenue as one sum
Minimum and Maximum
30The smallest and largest values.
The lowest and highest temperature of the week
Mean, Median and Standard Deviation
31Centre and spread - and the ddof setting that changes std.
A NumPy std that disagrees with Pandas until ddof is set
Variance
32Spread in squared units, and how it relates to std.
Two datasets with the same mean and very different variance
Percentiles and Quantiles
33The value below which a given share of the data falls.
The 90th percentile response time
argmin() and argmax()
34The position of the extreme, not its value.
Which student scored highest, not what they scored
Aggregation Along an Axis
35axis=0 down the columns, axis=1 across the rows.
An average per subject and an average per student from one table
Handling NaN Values
36isnan, and the nan-aware functions that skip missing data.
One NaN turning a whole mean into NaN
Shape, Reshaping and Broadcasting
Changing an array shape, and operating on different shapes
Understanding Array Shape
37Reasoning about axes - the skill reshaping and broadcasting both rely on.
Reading (32, 28, 28) as 32 images of 28 by 28 pixels
reshape()
38The 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
Flattening Arrays
39flatten always copies; ravel returns a view when it can.
Editing a raveled array and changing the original
Transpose
40Swapping axes with .T and np.transpose.
Rows of students turned into rows of subjects
Adding and Removing Dimensions
41expand_dims and squeeze, for shapes an API insists on.
One sample reshaped into a batch of one for a model
Broadcasting Fundamentals
42Operating on different shapes without copying data.
arr + 10 stretching the 10 across every element
Broadcasting Rules
43Compare shapes from the right; sizes must match or be 1.
A (3, 1) and a (4,) combining into a (3, 4)
Practical Broadcasting Examples
44Centring columns and pairwise differences, without loops.
Subtracting each column mean from every row in one line
Combining and Manipulating Arrays
Joining, splitting, sorting, and searching
Concatenating Arrays
45Joining arrays along an existing axis.
Two months of data combined into one array
Vertical and Horizontal Stacking
46vstack adds rows, hstack adds columns.
A new feature column added beside a dataset
Splitting Arrays
47split needs equal parts; array_split does not.
A dataset split into training and test portions
Adding and Removing Elements
48append, insert, and delete - each returning a brand new array.
np.append in a loop, and why it grows slowly
Sorting Arrays
49np.sort returns a copy; arr.sort sorts in place.
Sorting marks, and argsort to keep track of who scored them
Searching Arrays
50where to find or replace by condition; searchsorted for sorted data.
Negative values replaced with zero in one call
Unique Values
51Distinct values, and counting each one.
How many students got each grade
Advanced NumPy
Memory, types, and why NumPy is fast
Copy vs View
52When two arrays share memory, and how to tell.
A bug caused by editing what turned out to be a view
Data Types
53int32, int64, float32, float64, bool, and complex.
An int8 counter that overflowed without any error
Type Conversion
54astype, and the precision lost when narrowing.
Floats cast to integers and silently truncated
Structured Arrays
55Named, mixed-type fields in one array.
Names and scores stored in a single structured array
Memory Layout
56C-order against F-order, and contiguous memory.
The same sum faster along one axis than the other
Vectorization
57Replacing Python loops with whole-array operations.
A loop doubling every number, then numbers * 2
Vectorized Functions
58np.vectorize - convenient syntax, but still a loop underneath.
np.vectorize timed against a true array expression
Performance: Python Lists vs NumPy
59Measuring the gap honestly, including where lists win.
Ten elements where a list is faster, a million where it is not
Memory-Efficient NumPy Operations
60In-place operations, smaller dtypes, and avoiding temporary arrays.
A calculation that ran out of memory until it used out=
NumPy for Data Science and Machine Learning
Where arrays meet real datasets and models
Next: the Pandas course →NumPy for Data Analysis
61Loading, cleaning, and summarising a dataset with arrays alone.
Quick statistics on a dataset before reaching for Pandas
NumPy for Feature Data
62Rows as samples and columns as features.
Age and salary for three people as a 3 by 2 array
NumPy for Machine Learning
63Features, labels, the feature matrix X, and the target array y.
Splitting a dataset into X and y
Normalization with NumPy
64Scaling each feature to a 0 to 1 range.
Salary and age brought onto the same scale
Standardization with NumPy
65Zero mean and unit variance per feature.
Z-scores for every column in one broadcast expression
Distance Calculations
66Euclidean and Manhattan distance between points.
The nearest neighbour to one point, without a loop
Matrix Operations
67np.dot for dot products, and how it behaves in higher dimensions.
A weighted score as the dot product of weights and marks
Matrix Multiplication
68The @ operator, and the shapes that are allowed to multiply.
A (3, 2) @ (2, 4) giving a (3, 4)
Linear Algebra
69np.linalg - inverse, determinant, eigenvalues, and solving equations.
A system of equations solved with linalg.solve, not the inverse
NumPy with CSV Data
70loadtxt, genfromtxt, and savetxt - and their limits.
A CSV with a missing value that loadtxt cannot read
NumPy with Pandas
71A DataFrame column is a NumPy array underneath.
Moving between a DataFrame and an array, and back
NumPy with Scikit-learn
72How arrays flow through fit, transform, and predict.
A feature matrix passed into a model and predictions returned
NumPy Projects and Practice
Four projects, from student marks to an ML-ready dataset
Project 1 - Student Marks Analyzer
73Averages, extremes, subject averages, ranking, pass rates, and percentiles.
A full report card computed from one array of marks
Project 2 - Sales Data Analyzer
74Load, clean, aggregate, and summarise sales into business insights.
The best and worst months, and the products behind them
Project 3 - Image Data Processing
75An image as an array - brightness, cropping, grayscale, and transforms.
A colour photo turned grayscale with one weighted sum
Final Project - ML Dataset Preprocessor
76Missing values, outliers, normalisation, and standardisation into a feature matrix.
A raw dataset turned into one ready for a model