You now have the whole toolkit. This closing lesson shows it working on real data shapes — images and signals — where cropping is slicing, brightening is arithmetic, and flipping is indexing.
Images are arrays
A grayscale image is a 2-D array of intensities; a colour image is 3-D (height, width, 3). Every technique applies directly:
img = rng.integers(0, 256, (128, 128, 3), dtype=np.uint8)img[:64] # crop the top half (slicing)img[:, ::-1] # mirror horizontally (reverse the column axis)gray = img.mean(axis=2) # average channels → grayscalebright = np.clip(img * 1.2, 0, 255).astype(np.uint8) # brighten & clamp
Signals & series
signal = rng.normal(0, 1, 100).cumsum() # a random walkkernel = np.ones(5) / 5smooth = np.convolve(signal, kernel, mode="valid") # 5-point moving averagenp.diff(signal) # consecutive differences
Key takeaways
- 01Images are 2-D/3-D arrays: cropping is slicing, mirroring is indexing, grayscale is a channel mean.
- 021-D arrays are signals/series — smooth with np.convolve, find change with np.diff.
- 03np.clip bounds values into a range (e.g. 0–255 for pixels).
- 04NumPy is the base of the whole data/ML stack — these skills transfer everywhere.
