This course teaches you NumPy from scratch, with a basic-Python background assumed, and builds the math intuition (vectors, matrices, dot products) you need to start practising machine learning. By the end you will be comfortable creating and manipulating arrays, using broadcasting and vectorization instead of loops, doing core linear algebra with NumPy, and preparing real data for an ML model.
Who this course is for
Learners who know basic Python (variables, lists, loops, functions) but have not used NumPy before
People who want to start practising machine learning and need the array and math foundations first
Anyone who wants to replace slow Python loops with fast, vectorized code
Before you start
Basic Python: variables, lists, for loops, functions, and importing modules. No prior NumPy or linear algebra knowledge is assumed; both are built from zero inside the course.
Modules
1. Why NumPy, and what an array is
What it covers: Why plain Python lists are slow and inconvenient for numeric work, and what a NumPy array is at a high level.
Concepts: importing numpy as np, the ndarray object, comparing a Python list loop vs a NumPy array operation, where NumPy fits into the ML workflow
Common mistakes: thinking a NumPy array is just a fancier list, forgetting to import numpy as np
Practice ideas: convert a Python list of numbers to a NumPy array and print its type, add 1 to every element of a list using a loop then do the same with a NumPy array, time both approaches on a large list
Builds on: None
2. Creating arrays
What it covers: The main ways to create arrays directly, without converting from lists every time.
Common mistakes: confusing np.arange's exclusive stop with np.linspace's inclusive stop, forgetting np.zeros/np.ones take a shape tuple
Practice ideas: create a 1D array of 10 zeros, create a 3x3 array of ones, create a range from 0 to 20 in steps of 2 using arange, create 5 evenly spaced numbers between 0 and 1 using linspace, create a 4x4 identity matrix
Builds on: 1
3. Array attributes
What it covers: How to inspect an array's shape and size so you always know what you are working with.
Concepts: .shape, .ndim, .size, .dtype, reading a shape tuple for 1D, 2D and 3D arrays
Common mistakes: confusing shape (a tuple) with size (a single number), misreading which number in a shape tuple is rows vs columns
Practice ideas: create arrays of different dimensions and print shape, ndim and size for each, predict the shape of a given array before checking it, build a 2x3x4 array and explain what each shape number means
Builds on: 2
4. Data types in NumPy
What it covers: Why every NumPy array has a single fixed data type, and why this matters for memory and correctness in ML code.
Concepts: dtype, common dtypes (int32, int64, float32, float64, bool), specifying dtype at creation, converting with .astype()
Common mistakes: mixing int and float and being surprised by automatic upcasting, losing precision when converting float to int, assuming all elements can have different types like a list
Practice ideas: create an integer array and check its dtype, create the same array but force it to float32, convert a float array to int and observe what happens to decimals, create an array of True/False values and check its dtype
Builds on: 2, 3
5. Indexing and slicing 1D arrays
What it covers: How to access single elements and ranges of elements in a 1D array.
Concepts: positive and negative indexing, slicing with start:stop:step, omitting start or stop, reversing an array with a negative step
Common mistakes: forgetting slicing's stop index is exclusive, off-by-one errors with negative indices
Practice ideas: get the first and last element of an array, get every second element, get the last three elements, reverse the whole array, get elements from index 2 to 5
Builds on: 2
6. Indexing and slicing 2D arrays
What it covers: Extending indexing and slicing to rows, columns and submatrices in 2D arrays.
Concepts: array[row, col] syntax, selecting a full row, selecting a full column, slicing a submatrix with array[r1:r2, c1:c2]
Common mistakes: using array[row][col] instead of array[row, col] and not understanding why both can work differently, mixing up which index is row and which is column
Practice ideas: select a single element from a 2D array by row and column, extract the second row, extract the last column, extract a 2x2 submatrix from the corner, extract every other row
Builds on: 5, 3
7. Fancy indexing
What it covers: Selecting multiple, non-contiguous elements at once using lists or arrays of indices.
Concepts: indexing with a list of integers, fancy indexing on rows and columns together, the difference between fancy indexing (returns a copy) and slicing
Common mistakes: expecting fancy-indexed results to share memory with the original array like a slice does
Practice ideas: select elements at indices 0, 3 and 5 from a 1D array in one line, select rows 0 and 2 from a 2D array, select a custom set of rows and columns together, reorder an array using a list of indices
Builds on: 6
8. Boolean masking and filtering
What it covers: Selecting elements based on a condition, which is one of the most common operations in data preparation.
Concepts: comparison operators on arrays producing boolean arrays, using a boolean array to index, combining conditions with & and |, why plain Python and/or do not work on arrays
Common mistakes: using and/or instead of & and |, forgetting to wrap each condition in parentheses when combining them
Practice ideas: get all elements greater than 10 from an array, replace all negative numbers with 0 using a mask, count how many elements satisfy a condition, select elements that satisfy two conditions at once, filter rows of a 2D array based on one column's values
Builds on: 5, 6
9. Copies vs views
What it covers: Why some operations share memory with the original array and others don't, and why this causes confusing bugs if ignored.
Concepts: slicing returns a view, fancy indexing and boolean indexing return a copy, the .copy() method, checking shared memory with .base
Common mistakes: modifying a slice and being surprised the original array changed, assuming .copy() is unnecessary when it isn't
Practice ideas: slice an array, modify the slice, and check whether the original changed, do the same with fancy indexing and compare the result, explicitly create a copy with .copy() and show the original is now unaffected
Builds on: 5, 6, 7
10. Reshaping arrays
What it covers: Changing an array's shape without changing its data, a step used constantly when preparing data for models.
Concepts: .reshape(), using -1 to let NumPy infer a dimension, .flatten() vs .ravel(), when reshape fails due to incompatible size
Common mistakes: trying to reshape into a shape with a different total number of elements, confusing flatten (always a copy) with ravel (often a view)
Practice ideas: reshape a 1D array of 12 elements into a 3x4 array, reshape it again into 2x6, use -1 to reshape into 4 rows without calculating columns manually, flatten a 2D array back to 1D
Builds on: 3, 9
11. Transpose and axes intuition
What it covers: What it means to transpose an array, and building intuition for what an "axis" is in NumPy.
Concepts: .T attribute, np.transpose(), axis 0 vs axis 1 for 2D arrays, how axis choice affects row-wise vs column-wise operations
Common mistakes: confusing axis 0 with "horizontal" instead of "down the rows", expecting transpose to copy data by default
Practice ideas: transpose a 2x3 array and check its new shape, transpose a square matrix and compare before and after, predict the shape after transposing a 4x1 array
Builds on: 6, 10
12. Concatenation and stacking
What it covers: Joining two or more arrays together along a chosen axis.
Common mistakes: trying to concatenate arrays with mismatched shapes along the wrong axis, confusing stack (adds a new dimension) with concatenate (does not)
Practice ideas: stack two 1D arrays into a 2D array using vstack, join two 2D arrays side by side using hstack, concatenate three arrays along axis 0, use np.stack to combine arrays along a new axis
Builds on: 3, 11
13. Splitting arrays
What it covers: Breaking one array into several smaller arrays, the reverse of concatenation.
Concepts: np.split, np.hsplit, np.vsplit, splitting into equal parts vs specified indices
Common mistakes: trying to split into a number of parts that doesn't evenly divide the array
Practice ideas: split a 1D array of 10 elements into 5 equal parts, split a 2D array into two halves by rows, split a 2D array into two halves by columns, split an array at custom index positions
Builds on: 12
14. Arithmetic operations and vectorization
What it covers: Performing element-wise math directly on arrays, and why this is far faster than looping in Python.
Concepts: element-wise +, -, *, /, **, applying a function like np.sqrt or np.exp to a whole array, the idea of vectorization
Common mistakes: writing a manual for loop to do elementwise math out of habit, assuming * between arrays does matrix multiplication
Practice ideas: add two same-shaped arrays element-wise, square every element of an array without a loop, compute the square root of every element, compare the runtime of a loop-based computation vs its vectorized equivalent
Builds on: 2, 4
15. Broadcasting rules
What it covers: How NumPy lets you perform operations between arrays of different shapes, and the exact rule it follows to decide if this is allowed.
Concepts: the broadcasting rule (comparing shapes from the right, dimensions of size 1 stretch), adding a scalar to an array, adding a 1D array to a 2D array
Common mistakes: assuming any two shapes can broadcast, not checking shape compatibility before an operation and getting a confusing error
Practice ideas: add a single number to every element of an array, add a 1D array of length 3 to each row of a 3-column 2D array, predict whether two given shapes will broadcast before testing it, trigger and read a broadcasting error on purpose
Builds on: 14, 11
16. Broadcasting in practice
What it covers: Applying broadcasting to real data-preparation tasks like adjusting every row or column of a dataset at once.
Concepts: subtracting a row-wise mean from a 2D array, dividing each column by its own max, combining broadcasting with aggregation along an axis
Common mistakes: broadcasting along the wrong axis and silently getting wrong results, forgetting to reshape a 1D result before broadcasting it against columns
Practice ideas: subtract the mean of each column from a 2D dataset, scale each row of a matrix so its values sum to 1, center a dataset so every column has mean zero
Builds on: 15, 17
17. Aggregation functions and the axis parameter
What it covers: Summarizing array data with functions like sum and mean, and controlling the direction of the summary with the axis parameter.
Concepts: np.sum, np.mean, np.std, np.var, np.min, np.max, axis=0 vs axis=1, aggregating the whole array vs along one axis
Common mistakes: getting axis=0 and axis=1 backwards, forgetting that omitting axis aggregates the entire array into one number
Practice ideas: compute the overall mean of a 2D array, compute the mean of each column using axis=0, compute the mean of each row using axis=1, find the maximum value in each column, compute the standard deviation of the whole dataset
Builds on: 11, 14
18. Useful array functions
What it covers: A toolkit of frequently used NumPy functions for finding, sorting and transforming values.
Common mistakes: confusing argmax (returns an index) with max (returns a value), misusing np.where's three-argument form
Practice ideas: use np.where to replace values based on a condition, clip an array so all values stay between 0 and 1, find the unique values in an array, find the index of the largest value in an array, sort an array and separately get the sorting indices with argsort
Builds on: 8, 17
19. Vectors and the dot product
What it covers: What a vector is in the ML sense, and the geometric and computational meaning of the dot product.
Concepts: representing a vector as a 1D array, np.dot for vectors, the dot product as sum of elementwise products, dot product and similarity/angle intuition
Common mistakes: confusing the dot product (a single number) with elementwise multiplication (an array), trying to dot two vectors of different lengths
Practice ideas: compute the dot product of two vectors by hand with a loop, then check it matches np.dot, compute the dot product of two vectors representing feature weights and feature values, explain in words what a zero dot product between two vectors suggests
Builds on: 14
20. Matrix multiplication
What it covers: How matrix multiplication differs from elementwise multiplication, and the shape rule that determines whether two matrices can be multiplied.
Concepts: np.matmul, the @ operator, the inner-dimensions-must-match rule, resulting shape of a matrix product
Common mistakes: using * instead of @ or np.matmul for matrix multiplication, multiplying matrices whose shapes don't satisfy the inner-dimension rule
Practice ideas: multiply a 2x3 matrix by a 3x2 matrix and check the result's shape, predict the output shape of two given matrices before multiplying, multiply a matrix by a vector and interpret the result, show that A @ B is not the same as B @ A
Builds on: 19, 11
21. Linear algebra basics with numpy.linalg
What it covers: The core numpy.linalg tools used to describe and solve systems involving matrices.
Concepts: np.linalg.inv, np.linalg.det, np.linalg.solve, when a matrix is invertible
Common mistakes: trying to invert a non-square or singular matrix, using inv() to solve a linear system instead of the more direct solve()
Practice ideas: compute the determinant of a 2x2 matrix by hand then check with np.linalg.det, invert a matrix and multiply it by the original to confirm you get the identity matrix, solve a small system of linear equations with np.linalg.solve
Builds on: 20
22. Matrix properties relevant to ML
What it covers: A few matrix properties and shapes that come up constantly once you start building ML models.
Concepts: identity matrix, symmetric matrices, the shape convention of rows as samples and columns as features, diagonal of a matrix
Common mistakes: mixing up whether rows or columns represent samples in a dataset matrix
Practice ideas: build a dataset matrix with 5 samples and 3 features and identify its shape in words, extract the diagonal of a square matrix, check whether a given matrix is symmetric
Builds on: 20, 21
23. Random module basics
What it covers: Generating random numbers and arrays, used for initializing data, shuffling and simulation.
Common mistakes: confusing rand (uniform 0 to 1) with randn (normal distribution), forgetting randint's stop value is exclusive
Practice ideas: generate a 3x3 array of random numbers between 0 and 1, generate 10 random integers between 1 and 100, generate an array of 5 numbers from a standard normal distribution, randomly pick 3 elements from an existing array using choice
Builds on: 2
24. Reproducibility with random seeds
What it covers: Why ML experiments need reproducible randomness, and how to achieve it in NumPy.
Concepts: np.random.seed, why setting a seed makes "random" results repeatable, where to place the seed call
Common mistakes: setting the seed once and expecting every subsequent random call across a whole script to stay in sync with someone else's output, forgetting to set a seed before comparing results across runs
Practice ideas: set a seed, generate random numbers, rerun with the same seed and confirm identical output, generate numbers with two different seeds and confirm the outputs differ
Builds on: 23
25. Handling missing values
What it covers: Representing and working with missing or undefined values in numeric data, a near-universal step before training a model.
Concepts: np.nan, detecting missing values with np.isnan, nan-safe aggregation functions like np.nanmean and np.nansum, why ordinary mean breaks with NaN present
Common mistakes: using np.mean on data containing NaN and not noticing the result is NaN, comparing a value to np.nan with == instead of using np.isnan
Practice ideas: create an array containing some np.nan values, count how many values are missing using isnan, compute the mean of the array ignoring NaNs with nanmean, replace NaN values with the column mean
Builds on: 8, 17
26. Normalization and standardization
What it covers: The two standard ways of rescaling numeric features before feeding them into an ML model, and why models need this.
Concepts: min-max normalization formula, z-score standardization formula (subtract mean, divide by standard deviation), applying these per column using broadcasting
Common mistakes: normalizing across the whole flattened dataset instead of per feature/column, applying normalization before splitting into train and test sets in a way that leaks information
Practice ideas: min-max normalize a single array to the range 0 to 1, standardize an array so it has mean 0 and standard deviation 1, apply column-wise standardization to a small dataset matrix, verify the standardized result has mean approximately 0
Builds on: 16, 17, 25
27. Loading and saving data
What it covers: Getting real data into NumPy arrays and saving your results back out.
Concepts: np.loadtxt, np.genfromtxt for data with missing values, np.savetxt, np.save and np.load for NumPy's own binary format
Common mistakes: forgetting to set the correct delimiter when loading a CSV-like file, using loadtxt on a file that contains missing values instead of genfromtxt
Practice ideas: save a NumPy array to a .csv file with savetxt, load it back with loadtxt and confirm the values match, save an array in NumPy's .npy binary format and reload it with np.load, load a small CSV-style text file that contains a missing value using genfromtxt
Builds on: 2, 25
28. Splitting a dataset into train and test sets
What it covers: Using indexing and random shuffling together to split a dataset for training and evaluating a model, without using any ML library.
Concepts: shuffling row indices with np.random.permutation, choosing a split point, using fancy indexing to select train and test rows
Common mistakes: splitting the data without shuffling first when the rows are ordered by class or label, letting the same random split differ between runs because no seed was set
Practice ideas: shuffle the row indices of a dataset matrix using permutation, split the shuffled indices into 80 percent train and 20 percent test, use fancy indexing to create the actual train and test arrays, set a seed and confirm the split is identical on a second run
Builds on: 7, 23, 24
29. Mini project: linear regression with only NumPy
What it covers: Combining vectors, matrix multiplication, broadcasting and aggregation to implement simple linear regression from scratch, tying the whole course together.
Concepts: representing data as a feature matrix and target vector, the linear regression prediction formula as a dot product, computing mean squared error, a basic gradient descent update using vectorized operations
Common mistakes: mismatching the shapes of weights and features in the dot product, forgetting to average the gradient over all samples, using a learning rate that is too large and causing the loss to diverge
Practice ideas: build a small synthetic dataset with one feature and a known linear relationship, compute predictions for all samples at once using a dot product, compute the mean squared error between predictions and true values, write one gradient descent update step using vectorized NumPy operations, run several update steps in a loop and observe the loss decreasing