Week 1 Excercise -1 Zero_pad

I have padded the X and its shape is now: (4, 9, 9, 2). but when I ran the test it is throwing the below error. Am I not padding the correct way?

AssertionError Traceback (most recent call last)
in
12 axarr[1].set_title(‘x_pad’)
13 axarr[1].imshow(x_pad[0, :, :, 0])
—> 14 zero_pad_test(zero_pad)

~/work/release/W1A1/public_tests.py in zero_pad_test(target)
27
28 assert type(x_pad) == np.ndarray, “Output must be a np array”
—> 29 assert x_pad.shape == (5, 4 + 2 * pad, 4 + 2 * pad, 3), f"Wrong shape: {x_pad.shape} != {(5, 4 + 2 * pad, 4 + 2 * pad, 3)}"
30 assert np.allclose(x_pad[0, 0:2,:, 0], [[0, 0, 0, 0, 0, 0, 0, 0],
31 [0, 0, 0, 0, 0, 0, 0, 0]], 1e-15), “Rows are not padded with zeros”

AssertionError: Wrong shape: (5, 10, 10, 3) != (5, 8, 8, 3)

1 Like

Please click my name and message your notebook as an attachment.

Did you perhaps “hard-code” the pad value to 3, instead of using the pad argument? That will pass the first test, but fail the test where they use a pad value of 2. Hard-coding is generally not a good idea. :nerd_face:

1 Like

Yes, you are right Paul. Thanks!