I'm a beginner in Keras. I've loaded MNIST dataset in Keras and checked it's dimension. The code is
from keras.datasets import mnist # load data into train and test sets (X_train, y_train), (X_test, y_test) = mnist.load_data() print(X_train.shape) print(y_train.shape) print(X_test.shape) print(y_test.shape) print("Shape: ", X_train.shape)
And the output is
(60000, 28, 28, 1) (60000, 10, 2, 2, 2, 2) (10000, 28, 28, 1) (10000, 10, 2, 2) Shape: (28, 28, 1)
As X_train and X_test are already in the shape (#sample, width, height, #channel). Do we still need reshaping? Why? The tutorial I'm following use the following reshaping code:
X_train = X_train.reshape(X_train.shape, 28, 28, 1).astype('float32') X_test = X_test.reshape(X_test.shape, 28, 28, 1).astype('float32')
My second question is that why is
.astype('float32') is used in code?
Lastly, I could not understand the output of
Please suggest. I've already read Reshaping of data for deep learning using Keras however still my doubts are unclear.