First, we import the data. It is made up of 60,000 images for the training set and 10,000 images for the test set:
import tensorflow as tf
num_classes = 10
img_rows, img_cols = 28, 28
num_channels = 1
input_shape = (img_rows, img_cols, num_channels)
(x_train, y_train),(x_test, y_test) = tf.keras.datasets.mnist.load_data()
x_train, x_test = x_train / 255.0, x_test / 255.0
It is common practice to import TensorFlow with the alias tf for faster reading and typing. It is also common to use x to denote input data, and y to represent labels.
The tf.keras.datasets module provides quick access to download and instantiate a number of classical datasets. After importing the data using load_data, notice that we divide the array by 255.0 to get a number in the range [0, 1] instead of [0, 255]. It is common practice to normalize data, either in the [0, 1] range or in the [-1, 1] range.