Checkpoint: Numerical Computing
This checkpoint consolidates the numerical computing skills you just learned — coordinate grids, axis manipulation, dates, polynomial fitting, vectorization, and einsum — into one recap, a multi-step build challenge, and a short quiz.
Learn Checkpoint: Numerical Computing in our free NumPy course — a beginner-friendly interactive lesson with worked examples, a practice exercise and a quick…
Part of the free Numpy course at LearnCodingFast — hands-on lessons with examples you run in your browser, plus practice exercises and a quick quiz.
Work through the build challenge from the starter code, reveal the full solution to check yourself, then test your recall with the checkpoint quiz before moving on to the capstone.
What You've Learned in This Block
1 Quick Recap — The Tools at a Glance
Here is the whole block condensed into one reference table. Skim it, then put it to work in the build challenge below.
Goal
Code
Build a coordinate grid
X, Y = np.meshgrid(x, y)
Repeat a whole pattern
np.tile(arr, 3)
Repeat each element
np.repeat(arr, 3)
Make a column vector
arr[:, np.newaxis]
Transpose a matrix
m.T
Move an axis
np.moveaxis(a, 0, -1)
A range of dates
np.arange(d0, d1, dtype="datetime64[D]")
Fit a polynomial
np.polyfit(x, y, deg)
Vectorize a function
np.vectorize(func)
Matrix multiply with einsum
np.einsum("ij,jk->ik", A, B)
2 Warm-up: Recall the Patterns
Run this quick warm-up to refresh several tools from the block in one place before the bigger challenge.
🏗️ Build Challenge: From Grid to Trend to einsum
Put four tools from this block together in a single program:
- Build a coordinate grid with np.meshgrid and evaluate a surface Z = X**2 + Y**2 .
- Create noisy y data around a known line and recover the trend with np.polyfit .
- Use np.einsum to compute a weighted total of a small matrix.
- Print the shapes and key results so you can confirm each step.
Start from the scaffold, fill in the blanks, and run it. Then open the solution to compare.
🎯 YOUR TURN: Fill in the Blank
Combine a column and a row vector to broadcast a full addition table by filling in the indexing token.
Answer: newaxis (so a[:, np.newaxis] ). A column plus a row broadcasts into a 2D grid.
! Common Errors Across This Block
They produce very different layouts from the same input:
✅ Fix: tile stamps the whole block; repeat duplicates each element. Pick by the layout you need.
polyfit returns highest power first, so for a line it is [slope, intercept] .
✅ Fix: unpack as slope, intercept = coeffs for a degree-1 fit.
❌ Wrong einsum subscripts for matrix multiply
The shared axis must reuse a letter so it is contracted.
✅ Fix: matrix multiply is "ij,jk->ik" — the repeated j is summed away.
🎯 Mini Challenge: Distance Grid with a Trend
Build a grid, measure distance to a center, then summarize each row — mixing meshgrid, broadcasting, and axis sums.
📝 Checkpoint Quiz
Answer each in your head, then expand to check.
Two 2D arrays, X and Y. X holds the x-coordinate of every grid point and Y holds the y-coordinate, so X[i, j] paired with Y[i, j] is one (x, y) point — letting you evaluate f(x, y) over the whole grid at once.
np.tile([1, 2], 3) repeats the whole block to give [1, 2, 1, 2, 1, 2]. np.repeat([1, 2], 3) duplicates each element to give [1, 1, 1, 2, 2, 2].
Add a trailing axis with v[:, np.newaxis] (or v[:, None], or v.reshape(-1, 1)). np.expand_dims(v, axis=1) does the same thing.
No. .T and np.transpose return a view that shares the original data, so it is cheap — but writing into the transpose also writes into the original. Use .copy() for an independent array.
Highest power first, so [slope, intercept]. In general np.polyfit returns coefficients from the highest power down to the constant term.
np.einsum("ii->", M). The repeated i with no output letter selects the diagonal and sums it. To keep the diagonal as a vector instead, use "ii->i".
❓ Frequently Asked Questions
Checkpoint complete — numerical computing mastered!
You recapped meshgrid, tile and repeat, newaxis, transpose and swapaxes, datetime64, polynomials, vectorize, and einsum, and you wired several of them together in a build challenge.
🚀 Up next: Capstone — Image as an Array — bring the whole course together by treating a picture as a NumPy array.
Practice quiz
What does np.meshgrid(x, y) return?
- A single flattened array of coordinates
- One 2D array of distances
- Two 2D arrays X and Y holding the x and y coordinate of every grid point
- A list of (x, y) tuples
Answer: Two 2D arrays X and Y holding the x and y coordinate of every grid point. meshgrid returns two 2D arrays. X[i, j] paired with Y[i, j] is one (x, y) point, so you can evaluate f(x, y) over the whole grid at once.
How do np.tile and np.repeat differ on [1, 2] with count 3?
Continue this course
- Previous: Einstein Summation
- Next: Capstone: Image as an Array