Python and NumPy
Arrays, shapes and broadcasting, the habits that make ML code short and the bugs that make it confusing.
Why NumPy
NumPy is the Python library for fast arrays of numbers. A Python list holds objects and loops slowly. A NumPy array holds raw numbers in one block of memory and runs loops in compiled C.
- ML data is arrays: a table of examples is a 2-D array, an image is 3-D, a batch of images is 4-D.
- One NumPy expression often replaces a 5-line loop and runs 10 to 100 times faster.
- PyTorch, the deep learning library you will meet later, copies NumPy's ideas almost exactly.
1 of 7