Reshaping and resizing

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 resizetrainx <- array_reshape(trainx, c(nrow(trainx), 784))testx <- array_reshape(testx, c(nrow(testx), 784))trainx <- trainx / 255testx <- testx / 255str(trainx)OUTPUTnum [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 ...

Get Advanced Deep Learning with R now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.