Stage 1 · Lesson 9 of 9
Images as NumPy arrays
To a computer, a colour photo is just a of shape (height, width, 3): one number from 0 to 255 for the red, green and blue of every . Load a few images with Pillow and with and print their shape, dtype and a pixel value.
Crop by slicing, flip with [:, ::-1] and turn to greyscale by averaging channels, so the array stops feeling abstract. Two differences cause endless bugs later. OpenCV stores channels as BGR while almost everything else expects RGB, and wants channels first, (3, H, W), as floats rather than integers.
Common trapfeeding a model images in the wrong channel order or unscaled 0 to 255 values: it still trains, just badly, and nothing warns you.
A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock
Resources for this stage
Start with· follow one of these
- CoursePaidGrokking Python Fundamentals
Design Gurus · Beginner · $50
Core Python with an exercise after nearly every lesson, before the data libraries
- BookFreePython for Data Analysis, 3rd Edition
Wes McKinney · Beginner
Free online: NumPy, pandas and plotting from pandas' own creator