Week 1 Programming Assignment 1

For zero padding i am using this code :slight_smile:

{moderator edit - solution code removed}

Still it gives the error

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: (4, 7, 7, 2) != (5, 8, 8, 3)

The problem is that python is a case sensitive language. The argument to that function is X, but you are referencing x, which is a different variable. You must be picking up a global variable that happens to be the wrong shape. It’s always a mistake to reference global variables from the body of a function in these courses.

Wow! you are right it worked! These are the nuances i should pay attention to.

If it is news to you that python is case sensitive, that is a little worrying. Please note that all the DLS courses assume you are already a reasonably experienced python programmer. If that’s not the case, you might want to consider taking a python course first. Or if you are very experienced in some other languages like JavaScript, C# or C++, then you might just be able to read some of the tutorials on the python.org website.

Haven’t coded much on python off lately. I have been using more tools so lost touch but warming up with this course.