Exercise 3 - conv_forward - Got the code right but didn't understand it


I’ve got my code right but honestly, I didn’t understand how the loop is working espacilly for h and w loop, I had the reflexe that the loop must step by the stride.
If we take the example that is below the function, n_H_prev =5 so n_H = 3 and I don’t know how the h will be equal to 4 at the end of the loop.

to be clear, A_prev_pad in the example will have a shape of (2,7,9,4) so the h must pass by 0,2 and 4 but how the loop is set correct h can never be equal to 4.
and the same thing for the w where it must pass by 0,2,4,6 but will not in the loop

thanks in advance

If you skip by the stride, then you will be missing most of the examples.

The thing is I got my result correct, that’s why i didn’t get why

I deleted the stride, and I got it correct also I don’t understand this

1 Like

The test cases are bad: they don’t catch the error if you omit the stride. The grader catches it, though.

In terms of visualizing all this, it’s important to be clear about the difference between the input space and the output space. The loops are over the output space and we must not skip any positions there, but the striding happens in the input space.

1 Like

Thank you very much,
I understood where I got it wrong, I’ve solve it finally