This code is used in training model for image classification using Mnist dataset. what I don't understand is why we reshape the training images to (60000,28,28,1) instead of using it directly like this (60,28,28).
num_classes = 10
input_shape = (28, 28, 1)
(x_train, y_train), (x_test, y_test) = keras.datasets.mnist.load_data()
#print(x_train[0])
x_train = x_train.astype("float32") / 255
#print(x_train[0])
x_test = x_test.astype("float32") / 255
print(x_train.shape)
print(x_test.shape)
x_train = np.expand_dims(x_train, -1)
x_test = np.expand_dims(x_test, -1)
print("x_train shape:", x_train.shape)
print("x_train shape:", x_test.shape)
print(x_train.shape[0], "train samples")
print(x_test.shape[0], "test samples")
print()
print(y_train)
y_train = keras.utils.to_categorical(y_train, num_classes)
y_test = keras.utils.to_categorical(y_test, num_classes)
print()
print(y_train)