# DLS4 - Week1 - Exercise 3 - conv_forward

I know there are some previous similar contents regarding this error. But, I spent really much amount of time and still I haven’t figured it out. It seems there is a problem with horiz_start and horiz_end. Other than that, I checked other parameter dimensions and they seems to be correct. I am looping over 2, 5, 7 and 4 respectively. vert_start and horiz_start indexes are multiplied by stride. vert_end and horiz_end should include a summation of start and f.

I play with it so many times, but I think I might be confusing over it theoretically, not sure about it. Would anyone help me out please to resolve this issue?

Please make sure that you are not using the stride value in the “range” expression of your for loops. Note that the loops here are over the output space and we must touch each position of the output space and not skip any. The striding happens in the input space, so stride is used to calculate the vert_start and horiz_start positions on each iteration of the loops. But it sounds like you probably have that part right, so maybe you are also “striding” in the range of the loops.

Those “stride” are not located in the range of for loops. As I said, I am using that stride to compute the start indexes of vertical and horizontal. I feel like I am doing something wrong over the for loops.

what I see here is that if I change the for loop ranges : the h and w should be looped over n_H and n_W, respectively (i was doing n_H_prev and n_W_prev) and c = either n_C_pre or n_C_prev (those are the number of channels). In this case, it says the following:

As I mentioned above, the loops are over the output space, so the limits are n_H, n_W and n_C, right?

Exactly, those are the limits in my case. The error turns to “IndexError: index 4 is out of bounds for axis 3 with size 4” somehow

In the innermost for loop, we are basically getting Z from conv_single_step. Sending through 3 arguments into that function and getting Z. I couldn’t find out what the issue is now

If the loop limits are correct, then one other possibility is that your A_slice_prev value is the wrong shape. What shape is it? It should be the same on every iteration, right?

I added some instrumentation to my code. Here’s what I see running the very first test case for conv_forward:

``````stride 2 pad 1
New dimensions = 3 by 4
Shape Z = (2, 3, 4, 8)
Shape A_prev_pad = (2, 7, 9, 4)
a_prev_pad shape = (7, 9, 4)
Shape a_slice_prev = (3, 3, 4)
Z[0,0,0,0] = -2.651123629553914
Shape a_slice_prev = (3, 3, 4)
Shape a_slice_prev = (3, 3, 4)
Shape a_slice_prev = (3, 3, 4)
Shape a_slice_prev = (3, 3, 4)
Shape a_slice_prev = (3, 3, 4)
Shape a_slice_prev = (3, 3, 4)
Shape a_slice_prev = (3, 3, 4)
Shape a_slice_prev = (3, 3, 4)
Shape a_slice_prev = (3, 3, 4)
``````

How does that compare to what you see?

If I print the shape of a_slice_prev and Z[0, 0, 0, 0] in every iteration print(a_slice_prev.shape) and print(Z[0, 0, 0, 0]):

I keep consistently having the following output for a_slice_prev.shape and Z[0, 0, 0, 0];

(3, 3, 4)
-2.651123629553914
(3, 3, 4)
-2.651123629553914
(3, 3, 4)
-2.651123629553914
(3, 3, 4)
-2.651123629553914
(3, 3, 4)

It seems to be exactly same as what you printed out in your case

But I thought you were getting an error about index out of bounds. Where does that happen? Please show the complete exception trace you get from that error.

Just to close the loop here, we had some private conversations and found that the issue is the way that the Z value was being initialized in conv_forward. I should have asked to see the exception trace earlier.