6. NumPy¶
The Image class covers the per-pixel work the camera already knows how to do – thresholds, blob finding, edge detection, and the rest of the image library. The numpy module covers everything else: ADC readings and other buffers of plain numbers, math that runs across a whole buffer at once, and per-pixel transforms the image library has not already built in.
Enter the ndarray, a single class that holds a packed block of equally typed numbers. Everything else in numpy is a math function that operates on an ndarray. Adding two arrays together, summing one of them, taking a sine of every element – each is a single library call that processes the whole buffer in one go, much faster than the equivalent Python for loop.
Shape and indexing
Math
Linear algebra
Signal processing
Numerical tools
Performance
Wrap up