We're going to look at transformations on the training and test image data. For x_train and x_test, we need to do the following:
- Add a fourth dimension going from (60000, 28, 28) to (60000, 28, 28, 1),
- Change it to the Float32 data type.
- Normalize it between 0 and 1 (by dividing by 255).
In the following code block, we will perform normalization on the data:
x_train /=255
x_test /=255
print('x_train shape:', x_train.shape)
print(x_train.shape[0], 'train samples')
print(x_test.shape[0], 'test samples')
The shape of the data doesn't change after normalization:
x_train shape: (60000, 28, 28, 1) 60000 train samples 10000 test samples
In the next section, we will perform one-hot encoding on our target variables.