C1W3_Assignment Question

The image is reshaped into a 28x28 pixel array with 3 elements
Auto grader detects error when running this
How do I fix this?

Please remove code from the topic since the admins are likely to suspend your account. It’s okay to share stacktrace and message your code to a mentor though. Here’s the community user guide to get started.

In np.reshape, the shape specification should consider all the elements present in the original array.

Here’s a valid call since the product of shape parameter is 2*3 = 6 and is equal to the number of elements present in arr:

>>> import numpy as np
>>> arr = np.array([1, 2, 3, 4, 5, 6])
>>> np.reshape(arr, (2, 3))
array([[1, 2, 3],
       [4, 5, 6]])

The following is incorrect:

>>> np.reshape(arr, (2, ))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<__array_function__ internals>", line 5, in reshape

You can use -1 to indicate to numpy that the remaining elements fall within this dimension.

>>> np.reshape(arr, (-1, 2))
array([[1, 2],
       [3, 4],
       [5, 6]])

There are a couple of things to note in your code.

  1. The shape argument provided to me in the screenshot is different from the one in the notebook. The correct version should contain all the dimensions you want for the reshaped array.
  2. The return value of the tf.reshape operation is assigned to training_image and not training_images
  3. Use tf.cast to change the datatype of the image from uint8 to tf.float32

this the updated version

The notebook you just posted doesn’t contain the suggested fixes in the function reshape_and_normalize

Please don’t post your notebook in a public topic as the staff might suspend / revoke access to this forum.
Edit your reply and remove the notebook.

i am still staring at my notebook i dont understand what you mean by not having the suggested fixes i reshaped and normalized the in the function passed ,you can help understand better thankyou :pray: