Week 1 Ex 3: index out of bounds

I am running into an error in the big for loop of Exercise 3 of Week 1 's programming assignment. It looks that I am walking with a_slice_prev over a_prev_pad, but after the first c loop over slice [0:3;6:9] it comes with an “index out of bounce” error.

Since the error says “index = 3” I assume it has to do with the value of “w”, but I don’t get further than that.

Help is welcome!

See last printed values and error below

c loop
weights =
[[ 0.09542509 -0.18657899 -0.95542526]
[ 3.03085711 0.28267571 0.43816635]
[-0.16819884 -0.70134443 -1.94332341]]
slice i | vert_start | vert_end | horiz_start | horiz_end | c = 0 0 3 4 7 2
shape a_slice_prev = (3, 3)
shape weights = (3, 3)
shape biases = ()
a_slice_prev = (3, 3)
W = (3, 3)
s =
[[ 0. -0. -0. ]
[ 3.43629318 0.0119328 0.39504671]
[ 0.12567116 -0.13389751 -0.58332801]]
Z =
3.2517183304054553
Z float = 2.791775499564768
end
w loop
horiz_start = 6
horiz_end = 9
c loop
weights =
[[-0.78191168 -1.11647002 0.417302 ]
[ 1.3887794 -0.13597733 -0.23794194]
[-0.10999149 -0.19505734 -0.55749472]]
slice i | vert_start | vert_end | horiz_start | horiz_end | c = 0 0 3 6 9 0
shape a_slice_prev = (3, 3)
shape weights = (3, 3)
shape biases = ()
a_slice_prev = (3, 3)
W = (3, 3)
s =
[[-0. -0. 0. ]
[-1.52851724 -0.12249598 -0. ]
[-0.01321646 0.22285656 -0. ]]
Z =
-1.4413731203775124
Z float = -2.8401859390439887

IndexError Traceback (most recent call last)
in
6 “stride”: 2}
7
----> 8 Z, cache_conv = conv_forward(A_prev, W, b, hparameters)
9 z_mean = np.mean(Z)
10 z_0_2_1 = Z[0, 2, 1]

in conv_forward(A_prev, W, b, hparameters)
92 print("shape weights = ", weights.shape)
93 print("shape biases = ", biases.shape)
—> 94 Z[i, h, w, c] = conv_single_step(a_slice_prev, weights, biases)
95 print(“end”)
96 # YOUR CODE STARTS HERE

IndexError: index 3 is out of bounds for axis 2 with size 3

1 Like

Hey there,

Ensure that your loops are iterating over the correct ranges based on the dimensions. Carefully check the calculation of n_H and n_W.

1 Like

Tip: The ‘stride’ parameter should not be used in the “for” range statement.

1 Like