But to your original question, note that you can supply fewer indices to a tensor. E.g. if you index a 4D tensor with 3 indices, you fix the first three indices and then you enumerate the last dimension.
But in your case, it looks like Z is the wrong shape. The third dimension should have enough room for index 1 to be valid, but in your case it doesn’t.
I added some print statements to my code to show the dimensions of the various objects. A place to start would be to compare these shapes to what you are seeing.
New dimensions = 3 by 4
Shape Z = (2, 3, 4, 8)
Shape A_prev_pad = (2, 7, 9, 4)
a_prev_pad shape = (7, 9, 4)
Z[0,0,0,0] = -2.651123629553914
a_prev_pad shape = (7, 9, 4)
Z[1,2,3,7] = 0.4427056509973153
Z's mean =
0.5511276474566768
Z[0,2,1] =
[-2.17796037 8.07171329 -0.5772704 3.36286738 4.48113645 -2.89198428
10.99288867 3.03171932]
cache_conv[0][1][2][3] =
[-1.1191154 1.9560789 -0.3264995 -1.34267579]
New dimensions = 9 by 11
Shape Z = (2, 9, 11, 8)
Shape A_prev_pad = (2, 11, 13, 4)
a_prev_pad shape = (11, 13, 4)
Z[0,0,0,0] = -1.2238796505752447
a_prev_pad shape = (11, 13, 4)
Z[1,8,10,7] = -0.47458986707940803
New dimensions = 2 by 3
Shape Z = (2, 2, 3, 8)
Shape A_prev_pad = (2, 5, 7, 4)
a_prev_pad shape = (5, 7, 4)
Z[0,0,0,0] = 3.14880664541713
a_prev_pad shape = (5, 7, 4)
Z[1,1,2,7] = 1.0956417259542868
New dimensions = 13 by 15
Shape Z = (2, 13, 15, 8)
Shape A_prev_pad = (2, 17, 19, 4)
a_prev_pad shape = (17, 19, 4)
Z[0,0,0,0] = -0.5096687406137471
a_prev_pad shape = (17, 19, 4)
Z[1,12,14,7] = -0.3247422640409677
(2, 13, 15, 8)
New dimensions = 3 by 4
Shape Z = (2, 3, 4, 8)
Shape A_prev_pad = (2, 7, 9, 4)
a_prev_pad shape = (7, 9, 4)
Z[0,0,0,0] = -2.651123629553914
a_prev_pad shape = (7, 9, 4)
Z[1,2,3,7] = 0.4427056509973153
New dimensions = 3 by 4
Shape Z = (2, 3, 4, 8)
Shape A_prev_pad = (2, 7, 9, 4)
a_prev_pad shape = (7, 9, 4)
Z[0,0,0,0] = -2.651123629553914
a_prev_pad shape = (7, 9, 4)
Z[1,2,3,7] = 0.4427056509973153
New dimensions = 3 by 4
Shape Z = (2, 3, 4, 8)
Shape A_prev_pad = (2, 7, 9, 4)
a_prev_pad shape = (7, 9, 4)
Z[0,0,0,0] = -2.651123629553914
a_prev_pad shape = (7, 9, 4)
Z[1,2,3,7] = 0.4427056509973153
All tests passed.