Need help getting the following error
IndexError Traceback (most recent call last)
in
8 Z, cache_conv = conv_forward(A_prev, W, b, hparameters)
9 z_mean = np.mean(Z)
—> 10 z_0_2_1 = Z[0, 2, 1]
11 cache_0_1_2_3 = cache_conv[0][1][2][3]
12 print(“Z’s mean =\n”, z_mean)
IndexError: index 2 is out of bounds for axis 1 with size 2
Please mention the week and assignment number.
The thread Saif gave is definitely a great guide. If you also want to approach this just from a general debugging point of view, the error is telling you that your Z value is the wrong shape. So the first question is “Ok, what shape is it?” And then “What shape should it be?” I added some print statements to my conv_forward
logic to see what is going on and here’s what I get with correct code:
stride 2 pad 1
New dimensions = 3 by 4
Shape Z = (2, 3, 4, 8)
Shape A_prev_pad = (2, 7, 9, 4)
Z[0,0,0,0] = -2.651123629553914
Z[1,2,3,7] = 0.4427056509973153
Z's mean =
0.5511276474566768
Z[0,2,1] =
[-2.17796037 8.07171329 -0.5772704 3.36286738 4.48113645 -2.89198428
10.99288867 3.03171932]
cache_conv[0][1][2][3] =
[-1.1191154 1.9560789 -0.3264995 -1.34267579]
First Test: All tests passed!
So based on the wrong size you’ve got, it should tell you which section of that thread Saif points to is relevant to your mistake(s). 
Thanks Paual and Saif, these details helped me debug and solve the problem