Next, we reshape, train, and test data. We also divide the train and the test data by 255 to change the range of values from 0-255 to 0-1. The codes used are as follows:
# Reshape and resize
trainx <- array_reshape(trainx, c(nrow(trainx), 784))
testx <- array_reshape(testx, c(nrow(testx), 784))
trainx <- trainx / 255
testx <- testx / 255
str(trainx)
OUTPUT
num [1:60000, 1:784] 0 0 0 0 0 0 0 0 0 0 ...
The structure of the preceding trainx shows that after reshaping the train data, we now have data with 60,000 rows and 784 (28 x 28) columns.
We get the output of the histogram based on the first image (an ankle boot) in the train data after dividing the data by 255, as shown in the following screenshot:
The preceding histogram shows that the range of data points has now changed to values between 0 and 1. However, the shape observed in the previous histogram has not changed.