Converting images to matrices

Much of machine learning is just operations on matrices. We will start that process next by converting our images into a series of matrices—essentially, a 3D matrix as wide as the number of images we have.

Almost all matrix operations that we will perform in this chapter, and the entire book, use NumPy—the most popular scientific computing package in the Python landscape. NumPy is available at http://www.numpy.org/. You should install it before running the next series of operations.

The following code opens images and creates the matrices of data (note the three extra imports now required):

 import numpy as np from IPython.display import display, Image from scipy import ndimage image_size = 28 # Pixel width and ...

Get Machine Learning with TensorFlow 1.x now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.