Course 4 week 1 exercise 3

Hi I have been getting the following error.

IndexError Traceback (most recent call last)
in
8 Z, cache_conv = conv_forward(A_prev, W, b, hparameters)
9 print(“Z’s mean =\n”, np.mean(Z))
—> 10 print(“Z[0,2,1] =\n”, Z[0, 2, 1])
11 print(“cache_conv[0][1][2][3] =\n”, cache_conv[0][1][2][3])
12

IndexError: index 2 is out of bounds for axis 1 with size 2
I thought Z was 4 dimensional so why is it being indexed by 3 only?
How do I fix this error?

Never mind I was able to fix the error. I forgot to add by 1 in the n_H,n_W formula.
But I now have a different error.
AssertionError Traceback (most recent call last)
in
11 print(“cache_conv[0][1][2][3] =\n”, cache_conv[0][1][2][3])
12
—> 13 conv_forward_test(conv_forward)

~/work/release/W1A1/public_tests.py in conv_forward_test(target)
118 ]
119
→ 120 multiple_test(test_cases, target)
121
122

~/work/release/W1A1/test_utils.py in multiple_test(test_cases, target)
151 print(’\033[91m’, len(test_cases) - success, " Tests failed")
152 raise AssertionError(
→ 153 “Not all tests were passed for {}. Check your equations and avoid using global variables inside the function.”.format(target.name))

AssertionError: Not all tests were passed for conv_forward. Check your equations and avoid using global variables inside the function.
Does anyone have any hints?

That error from “mutliple_test()” means that for one of the variables returned by conf_forward(), either the data type, shape, or value were incorrect.

Unfortunately the error message doesn’t tell you which one.

The easiest way to diagnose the problem is if you send me your code for the conf_forward() function via a private message.

Hi @bhavna,

Make sure you are using variables that are present within the function.
For example, does the function have argument image but img was defined earlier and you are using img for the later stages? In that case, the function will not throw errors but it would be working with wrong variable!