while working on the function conv_forward(): the interpreter is throwing following error -
IndexError: index 4 is out of bounds for axis 2 with size 4. what am i doing wrong?
Basically you have a mismatch between container shape and where you’re trying to store into it. Either Z is too small (check how it was initialized) or w is too big (check your loop control/ range limit)
Exactly. There are lots of possibilities for how such an error could happen. The thing that most commonly trips people up is not handling the stride correctly, e.g. implementing the stride in the output space, but it should be happening in the input space, right? Or mixing up the h and w dimensions. Remember that h is for “height”, not “horizontal”. In this case the w dimension is bigger than the h dimension on the inputs, so that will be true in the outputs as well.
What should the output dimension be? The formula is:
n_{out} = \displaystyle \lfloor \frac {n_{in} + 2p - f}{s} \rfloor + 1
For axis = 2, that would be the w dimension so we have n_{in} = 7, f = 3, p = 1 and s = 2, so that comes out to n_{out} = 4. It looks like your Z is the right shape (at least in that dimension), but your indexing is wrong. So it’s the limits on your for loop that are probably wrong.
thanks for your explanation