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.

Here is the whole block condensed into one reference table. Skim it, then put it to work in the build challenge below.

Run this quick warm-up to refresh several tools from the block in one place before the bigger challenge.

Put four tools from this block together in a single program:

Start from the scaffold, fill in the blanks, and run it. Then open the solution to compare.

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.

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.

Build a grid, measure distance to a center, then summarize each row — mixing meshgrid, broadcasting, and axis sums.

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".

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?