Reshaping and normalizing

Please help me to find my mistake in reshaping and normalizing function as it is incorrect with expected values:

here is my function:

def reshape_and_normalize(images):

### START CODE HERE

# Reshape the images to add an extra dimension
images=training_images.reshape(60000, 28, 28, 1)

# Normalize pixel values

images = training_images/255.0

### END CODE HERE

return images

results i get:

Maximum pixel value after normalization: 1.0 Shape of training set after reshaping: (60000, 28, 28) Shape of one image after reshaping: (28, 28)

Expected Output:

Maximum pixel value after normalization: 1.0 Shape of training set after reshaping: (60000, 28, 28, 1) Shape of one image after reshaping: (28, 28, 1)

what is wrong?

Make use of images parameter consistently (i.e. don’t use training_images). In your code, the reshaped array is lost due to incorrect assignments.

3 Likes