from tensorflow.keras.datasets import mnist from tensorflow.keras.utils import to_categorical import numpy as np (x_train, y_train), (x_test, y_test) = mnist.load_data() x_train = x_train.astype("float32") / 255.0 x_test = x_test.astype("float32") / 255.0 x_train = x_train[..., np.newaxis] x_test = x_test[..., np.newaxis] y_train = to_categorical(y_train, 10) y_test = to_categorical(y_test, 10)