- Apache Spark Deep Learning Cookbook
- Ahmed Sherif Amrith Ravindra
- 232字
- 2025-02-26 11:49:45
How it works...
This section will walk through the process of how the MNIST handwritten images are viewed in a Jupyter notebook:
- A loop is generated in Python that will sample two images from the training dataset.
- Initially, the images are just a series of values in float format between 0 and 1 that are stored in a numpy array. The value of the array is a labeled image called image. The image array is then reshaped into a 28 x 28 matrix called pixels that has a black color for any value at 0 and a gray shade color for any color that is not 0. The higher the value, the lighter the gray shade of color. An example can be seen in the following screenshot for the digit 8:

- The output of the loop produces two handwritten images for the numbers 7 and 3 along with their labels, as seen in the following screenshot:

- In addition to the images being plotted, the label from the training dataset is also printed above the image. The label is an array of length 10, with values of 0 or 1 only for all 10 digits. For digit 7, the 8th element in the array is of value 1 and for digit 3, the 4th element in the array is of value 1. All other values are 0.