Course 4, week 1, Convolution_model_Step_by_Step_v1, Exercise 3 - unable to overcome shapes error

I made the point earlier that you can either use multiplication or addition for handling the stride. Watch this:

stride = 3

print("Using multiplication")
for h in range(4):
    vert_start = h * stride
    print(f"h {h}, vert_start {vert_start}")

print("Using addition")
vert_start = 0
for h in range(4):
    print(f"h {h}, vert_start {vert_start}")
    vert_start = vert_start + stride

Running that gives these results:

Using multiplication
h 0, vert_start 0
h 1, vert_start 3
h 2, vert_start 6
h 3, vert_start 9
Using addition
h 0, vert_start 0
h 1, vert_start 3
h 2, vert_start 6
h 3, vert_start 9

So either method works, but I think the multiplication method is simpler to write and clearer code.

1 Like