C4_W1_3.3: IndexError

Hello there,

I’ve got an IndexError, telling me the following:

IndexError                                Traceback (most recent call last)
<ipython-input-34-182241fd5e53> in <module>
      6                "stride": 2}
----> 8 Z, cache_conv = conv_forward(A_prev, W, b, hparameters)
      9 print("Z's mean =\n", np.mean(Z))
     10 print("Z[0,2,1] =\n", Z[0, 2, 1])

<ipython-input-33-0b0f39714a47> in conv_forward(A_prev, W, b, hparameters)
     81                     weights = W[...,c]
     82                     biases = b[...,c]
---> 83                     Z[i, h, w, c] = conv_single_step(a_slice_prev, weights, biases)
     84     # YOUR CODE ENDS HERE

IndexError: index 4 is out of bounds for axis 1 with size 4

I’m not really sure where the problem is, and read through a few threads, but couldn’t make out my mistake. I’d appreciate any hints, I’m completely stuck! :slight_smile:

The most common problem is if your code (or results) for a_slice_prev is incorrect.

I played around with my implementation of a_slice_prev. At least the size of (3, 3, 4) seems to be in order, but I can’t figure out, why I’ve got the indexerror.

                    vert_start = h
                    vert_end = h + f 
                    horiz_start = w
                    horiz_end = w + f
                    a_slice_prev = a_prev_pad[vert_start:vert_end, horiz_start:horiz_end,:]

The start values need to include multiplication by “stride”.

Thank you, that solved the IndexError, but I am now stuck with an

ValueError: operands could not be broadcast together with shapes (3,0,4) (3,3,4)