Index 4 is out of bounds for axis 2 with size 4

Good day! I studied the error in the conv_forward exercise:

I’m confused.
Thank you for your time

The index out of bounds error means you are trying to access an element of a tensors (matrix) that does not exist. More specifically the second dimension here (and keep in mind it should start from the zeroth dimension as far as I remember) is less than 4, thats why you get the error.


Z[i, h, w, c] = … is an assignment of a value into an indexed location in the Z matrix you defined. Since you’re getting an exception, either the location index is incorrect (too big) or Z was initialized incorrectly (too small). First confirm correct shape for Z. Then look at your loop ranges and check how you incorporate stride.

You could probably benefit from looking at a few of these threads…


Thank you. The error was in “for h in range” and “for w in range”, as well as in biases.