Why to divide x_train by 255.0? if using mnsit dataset

import tensorflow as tf
import numpy as np

(x_train, y_train), (x_test,y_test)= tf.keras.datasets.mnist.load_data()

x_train = x_train / np.float32(255)
y_train = y_train.astype(np.int64)
# The `x` arrays are in uint8 and have values in the [0, 255] range.  # You need to convert them to float32 with values in the [0, 1] range.

Why we have to convert it

1 Like

This normalizes the data so the range of values are limited. This helps the mathematical algorithms to efficiently find the weight values that give the lowest cost.