NumPy in practice

Linear algebra with @ and np.linalg, random numbers and simulation with seeded generators, and images as arrays.

About 6 hours of study

Learning objectives

Lessons

  1. 1

    Linear algebra with NumPy Advanced

    Vectors and matrices in NumPy: dot products, the @ operator for matrix multiplication and its shape rule, the identity, the determinant and inverse, and solving systems of equations with np.linalg.solve.

  2. 2

    Random numbers and simulation Intermediate

    NumPy's random generator: default_rng and seeds for reproducible results, integers, random, normal and choice, shuffling and permutations, how a pseudo-random generator works, and Monte Carlo estimates with their error.

  3. 3

    NumPy in practice: images as arrays Advanced

    Putting NumPy to work on images: pixels as uint8 arrays with shape (height, width) or (height, width, 3), cropping and flipping with slices, brightness changes with clipping and the uint8 overflow trap, masks and simple filters.

Module practice

Module quiz

1. Which operator multiplies matrices?
2. What does a seed make possible?
3. A greyscale image of 100 rows and 200 columns has shape…
4. What is the determinant of [[2, 1], [4, 2]]?
5. rng.integers(0, 10, size=3) can include…
6. Why convert an image to int16 before adding brightness?

‹ Shaping, ordering and statisticsFinal assessment ›