Stuck at conv_forward() in C4W1

Hi all,

I know that I am not the first one to encounter this issue and looked at all other topics on the same subject but I have not found the solution to my problem and I am stuck. My conv_forward() function results in an error:
Z’s mean =
Z[0,2,1] =
[0. 0. 0. 0. 0. 0. 0. 0.]
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: Not all tests were passed for conv_forward. Check your equations and avoid using global variables inside the function.

Z[0,2,1] should certainly not contain only zeros. I am not sure of the slicing and did my for loop like this:

for i in range(m):
a_prev_pad = A_prev_pad[i]
for h in range(n_H-2):
vert_start = h*stride
vert_end = (h+1)stride
for w in range(n_W-2):
horiz_start = w
horiz_end = (w+1)*stride
for c in range(n_C):
a_slice_prev = a_prev_pad[vert_start:vert_end,horiz_start:horiz_end,:]
weights = W[vert_start:vert_end,horiz_start:horiz_end,:,c]
biases = b[0,0,0,c]
Z[i,h,w,c]=conv_single_step(a_slice_prev, weights, biases)

Can someone give me a hint ?

I can’t read your code very well because you posted it without any indentation (which is crucial for python syntax).

Please use the “preformatted text” tag when you post your code.

I can spot that your ranges for h and w are incorrect. You don’t need to subtract anything. And you don’t need to add one for the end indices.

For slicing the weights and biases, use [:,:,:,c].

Thank you very much, I managed to see where the error was. Indeed the size of the ranges h and w were wrong, I did not take into account the filter size.