Hello.
I got this error in exercise 3
Z’s mean =
nan
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 0
Can anyone help me to solve the problem?
Hi Lilit.Ghalachyan,
The error indicates that you do not calculate Z correctly, so its mean cannot be calculated and it cannot be indexed into.
So you need to look at your code and see whether you initialize Z and calculate its value correctly.
I wrote for Z
Z = np.zeros((m, n_H, n_W, n_C))
and also
for c in range(n_C):
a_slice_prev =a_prev_pad[vert_start:vert_end,horiz_start:horiz_end,:]
weights=W[:,:,:,c]
biases =b[:,:,:,c]
Z[i, h, w, c] = conv_single_step(a_slice_prev, weights, biases)
Can not find the mistake.
I also made some corrections and got this error.
Z’s mean =
0.2999719807951914
Z[0,2,1] =
[ 3.07229898 -2.60921766 -1.63280904 5.71720329 1.18903119 0.90610057
9.2941049 5.13892311]
cache_conv[0][1][2][3] =
[-1.1191154 1.9560789 -0.3264995 -1.34267579]
(2, 13, 15, 8)
Error: Wrong output for variable in position 0.
2 Tests passed
1 Tests failed
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.
I have just solved my problem, thank you.
can you please tell how you have sloved?