C4:W1:A1: Ex 3: z_0_2_1 = Z[0, 2, 1],IndexError: index 2 is out of bounds for axis 1 with size 1. Isn't that Z a 4-rank array?

Hi all,

I’m here to get help with an error that occurs in C4:W1:A1: Ex 3: conv_forward(A_prev, W, b, parameters). It is returning Z having 4 ranks because it is Z[i,h,w,c]=something in the function. I put Z[i,h,w,c]=conv_single_step(a_slice_prev, weights,biases). In the test trunk, there is z_0_2_1 = Z[0, 2, 1]. This gave the error as: IndexError: index 2 is out of bounds for axis 1 with size 1.

I may have missed something. Can anyone help me with this problem? Thanks ahead!

A very common issue in the conv_forward() function is how your code handles computing the start and end indices.

  • ‘stride’ should not be used as a range() parameter.
  • the vertical indices use ‘h’. The horizontal indices use ‘w’.

It’s also possible that the error is in your conv_single_step() function.

Thanks for the quick reply. I checked stride, h, and w and I found that I have used stride in range, that’s not right. :sweat_smile: I corrected the range and the shape of Z is correct now.

1 Like