Skip to main content
Albero Academy

NumPy in Practice

Images and signals as arrays — everything you learned, on real data shapes.

Applied NumPy9 min

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:

image ops = array ops
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 → grayscale
bright = np.clip(img * 1.2, 0, 255).astype(np.uint8) # brighten & clamp

Signals & series

smoothing & differencing
signal = rng.normal(0, 1, 100).cumsum() # a random walk
kernel = np.ones(5) / 5
smooth = np.convolve(signal, kernel, mode="valid") # 5-point moving average
np.diff(signal) # consecutive differences

Key takeaways

  1. 01Images are 2-D/3-D arrays: cropping is slicing, mirroring is indexing, grayscale is a channel mean.
  2. 021-D arrays are signals/series — smooth with np.convolve, find change with np.diff.
  3. 03np.clip bounds values into a range (e.g. 0–255 for pixels).
  4. 04NumPy is the base of the whole data/ML stack — these skills transfer everywhere.

Finished this chapter?

Mark it complete to track your progress through NumPy.