Course 4, Week 1, Conv_forward Looping over vertical and horizontal axis


This may seem like a simple/silly question but I am having trouble thinking of the lines of code I’d need to write in order to loop over the vertical and horizontal axis of the output volume. So far my code is looking like this.

So far I’m pretty sure I’ve iterated through the batch of training examples properly. To iterate through the vertical axis would the line I write be " for h in a_prev_pad[i][1] "?

You need to compute the dimensions of the output space first, right? They gave you the formula:

n_{out} = \displaystyle \lfloor \frac {n_{in} + 2p - f}{s} \rfloor + 1

Those funny looking brackets there are the “floor” function, which is necessary because the denominator may not evenly divide the numerator.

Also note that doing indexing into a_prev_pad is not what you want in any case: that will give you some element of a_prev_pad, which will be a) a floating point number and b) nothing to do with the size of the object.