DLS Course 4 -- W1 -- Assignment1 - EX3

Hi, I am having trouble figuring out what is causing the problem in my implementation. I have read several threads about this problem and tried some of the suggestions mentioned but unfortunately, it did not work for me. I tried tracing my code by hand and it did work as intended but when I print the results of my code it differs in horiz 6:9 for every value of vert. I do not know why the shape of a_slice_prev is (1,3,4) only for these value of horiz .

Any suggestions on what might be the problem?

InPut shape after padding with pad = 1:  (2, 7, 9, 4)
OutPut shape:  (2, 3, 4, 8)
Z[0,0,0,0]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  0:3
Z[0,0,0,1]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  0:3
Z[0,0,0,2]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  0:3
Z[0,0,0,3]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  0:3
Z[0,0,0,4]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  0:3
Z[0,0,0,5]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  0:3
Z[0,0,0,6]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  0:3
Z[0,0,0,7]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  0:3
Z[0,0,1,0]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  2:5
Z[0,0,1,1]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  2:5
Z[0,0,1,2]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  2:5
Z[0,0,1,3]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  2:5
Z[0,0,1,4]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  2:5
Z[0,0,1,5]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  2:5
Z[0,0,1,6]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  2:5
Z[0,0,1,7]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  2:5
Z[0,0,2,0]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  4:7
Z[0,0,2,1]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  4:7
Z[0,0,2,2]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  4:7
Z[0,0,2,3]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  4:7
Z[0,0,2,4]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  4:7
Z[0,0,2,5]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  4:7
Z[0,0,2,6]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  4:7
Z[0,0,2,7]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  4:7
Z[0,0,3,0]      a_slice_prev.shape  (1, 3, 4)    vert  0:3    horiz  6:9
Z[0,0,3,1]      a_slice_prev.shape  (1, 3, 4)    vert  0:3    horiz  6:9
Z[0,0,3,2]      a_slice_prev.shape  (1, 3, 4)    vert  0:3    horiz  6:9
Z[0,0,3,3]      a_slice_prev.shape  (1, 3, 4)    vert  0:3    horiz  6:9
Z[0,0,3,4]      a_slice_prev.shape  (1, 3, 4)    vert  0:3    horiz  6:9
Z[0,0,3,5]      a_slice_prev.shape  (1, 3, 4)    vert  0:3    horiz  6:9
Z[0,0,3,6]      a_slice_prev.shape  (1, 3, 4)    vert  0:3    horiz  6:9
Z[0,0,3,7]      a_slice_prev.shape  (1, 3, 4)    vert  0:3    horiz  6:9
Z[0,1,0,0]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  0:3
Z[0,1,0,1]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  0:3
Z[0,1,0,2]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  0:3
Z[0,1,0,3]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  0:3
Z[0,1,0,4]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  0:3
Z[0,1,0,5]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  0:3
Z[0,1,0,6]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  0:3
Z[0,1,0,7]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  0:3
Z[0,1,1,0]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  2:5
Z[0,1,1,1]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  2:5
Z[0,1,1,2]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  2:5
Z[0,1,1,3]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  2:5
Z[0,1,1,4]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  2:5
Z[0,1,1,5]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  2:5
Z[0,1,1,6]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  2:5
Z[0,1,1,7]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  2:5
Z[0,1,2,0]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  4:7
Z[0,1,2,1]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  4:7
Z[0,1,2,2]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  4:7
Z[0,1,2,3]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  4:7
Z[0,1,2,4]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  4:7
Z[0,1,2,5]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  4:7
Z[0,1,2,6]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  4:7
Z[0,1,2,7]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  4:7
Z[0,1,3,0]      a_slice_prev.shape  (1, 3, 4)    vert  2:5    horiz  6:9
Z[0,1,3,1]      a_slice_prev.shape  (1, 3, 4)    vert  2:5    horiz  6:9
Z[0,1,3,2]      a_slice_prev.shape  (1, 3, 4)    vert  2:5    horiz  6:9
Z[0,1,3,3]      a_slice_prev.shape  (1, 3, 4)    vert  2:5    horiz  6:9
Z[0,1,3,4]      a_slice_prev.shape  (1, 3, 4)    vert  2:5    horiz  6:9
Z[0,1,3,5]      a_slice_prev.shape  (1, 3, 4)    vert  2:5    horiz  6:9
Z[0,1,3,6]      a_slice_prev.shape  (1, 3, 4)    vert  2:5    horiz  6:9
Z[0,1,3,7]      a_slice_prev.shape  (1, 3, 4)    vert  2:5    horiz  6:9
Z[0,2,0,0]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  0:3
Z[0,2,0,1]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  0:3
Z[0,2,0,2]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  0:3
Z[0,2,0,3]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  0:3
Z[0,2,0,4]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  0:3
Z[0,2,0,5]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  0:3
Z[0,2,0,6]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  0:3
Z[0,2,0,7]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  0:3
Z[0,2,1,0]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  2:5
Z[0,2,1,1]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  2:5
Z[0,2,1,2]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  2:5
Z[0,2,1,3]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  2:5
Z[0,2,1,4]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  2:5
Z[0,2,1,5]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  2:5
Z[0,2,1,6]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  2:5
Z[0,2,1,7]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  2:5
Z[0,2,2,0]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  4:7
Z[0,2,2,1]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  4:7
Z[0,2,2,2]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  4:7
Z[0,2,2,3]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  4:7
Z[0,2,2,4]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  4:7
Z[0,2,2,5]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  4:7
Z[0,2,2,6]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  4:7
Z[0,2,2,7]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  4:7
Z[0,2,3,0]      a_slice_prev.shape  (1, 3, 4)    vert  4:7    horiz  6:9
Z[0,2,3,1]      a_slice_prev.shape  (1, 3, 4)    vert  4:7    horiz  6:9
Z[0,2,3,2]      a_slice_prev.shape  (1, 3, 4)    vert  4:7    horiz  6:9
Z[0,2,3,3]      a_slice_prev.shape  (1, 3, 4)    vert  4:7    horiz  6:9
Z[0,2,3,4]      a_slice_prev.shape  (1, 3, 4)    vert  4:7    horiz  6:9
Z[0,2,3,5]      a_slice_prev.shape  (1, 3, 4)    vert  4:7    horiz  6:9
Z[0,2,3,6]      a_slice_prev.shape  (1, 3, 4)    vert  4:7    horiz  6:9
Z[0,2,3,7]      a_slice_prev.shape  (1, 3, 4)    vert  4:7    horiz  6:9
Z[1,0,0,0]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  0:3
Z[1,0,0,1]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  0:3
Z[1,0,0,2]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  0:3
Z[1,0,0,3]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  0:3
Z[1,0,0,4]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  0:3
Z[1,0,0,5]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  0:3
Z[1,0,0,6]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  0:3
Z[1,0,0,7]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  0:3
Z[1,0,1,0]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  2:5
Z[1,0,1,1]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  2:5
Z[1,0,1,2]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  2:5
Z[1,0,1,3]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  2:5
Z[1,0,1,4]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  2:5
Z[1,0,1,5]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  2:5
Z[1,0,1,6]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  2:5
Z[1,0,1,7]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  2:5
Z[1,0,2,0]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  4:7
Z[1,0,2,1]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  4:7
Z[1,0,2,2]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  4:7
Z[1,0,2,3]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  4:7
Z[1,0,2,4]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  4:7
Z[1,0,2,5]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  4:7
Z[1,0,2,6]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  4:7
Z[1,0,2,7]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  4:7
Z[1,0,3,0]      a_slice_prev.shape  (1, 3, 4)    vert  0:3    horiz  6:9
Z[1,0,3,1]      a_slice_prev.shape  (1, 3, 4)    vert  0:3    horiz  6:9
Z[1,0,3,2]      a_slice_prev.shape  (1, 3, 4)    vert  0:3    horiz  6:9
Z[1,0,3,3]      a_slice_prev.shape  (1, 3, 4)    vert  0:3    horiz  6:9
Z[1,0,3,4]      a_slice_prev.shape  (1, 3, 4)    vert  0:3    horiz  6:9
Z[1,0,3,5]      a_slice_prev.shape  (1, 3, 4)    vert  0:3    horiz  6:9
Z[1,0,3,6]      a_slice_prev.shape  (1, 3, 4)    vert  0:3    horiz  6:9
Z[1,0,3,7]      a_slice_prev.shape  (1, 3, 4)    vert  0:3    horiz  6:9
Z[1,1,0,0]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  0:3
Z[1,1,0,1]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  0:3
Z[1,1,0,2]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  0:3
Z[1,1,0,3]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  0:3
Z[1,1,0,4]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  0:3
Z[1,1,0,5]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  0:3
Z[1,1,0,6]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  0:3
Z[1,1,0,7]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  0:3
Z[1,1,1,0]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  2:5
Z[1,1,1,1]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  2:5
Z[1,1,1,2]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  2:5
Z[1,1,1,3]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  2:5
Z[1,1,1,4]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  2:5
Z[1,1,1,5]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  2:5
Z[1,1,1,6]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  2:5
Z[1,1,1,7]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  2:5
Z[1,1,2,0]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  4:7
Z[1,1,2,1]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  4:7
Z[1,1,2,2]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  4:7
Z[1,1,2,3]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  4:7
Z[1,1,2,4]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  4:7
Z[1,1,2,5]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  4:7
Z[1,1,2,6]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  4:7
Z[1,1,2,7]      a_slice_prev.shape  (3, 3, 4)    vert  2:5    horiz  4:7
Z[1,1,3,0]      a_slice_prev.shape  (1, 3, 4)    vert  2:5    horiz  6:9
Z[1,1,3,1]      a_slice_prev.shape  (1, 3, 4)    vert  2:5    horiz  6:9
Z[1,1,3,2]      a_slice_prev.shape  (1, 3, 4)    vert  2:5    horiz  6:9
Z[1,1,3,3]      a_slice_prev.shape  (1, 3, 4)    vert  2:5    horiz  6:9
Z[1,1,3,4]      a_slice_prev.shape  (1, 3, 4)    vert  2:5    horiz  6:9
Z[1,1,3,5]      a_slice_prev.shape  (1, 3, 4)    vert  2:5    horiz  6:9
Z[1,1,3,6]      a_slice_prev.shape  (1, 3, 4)    vert  2:5    horiz  6:9
Z[1,1,3,7]      a_slice_prev.shape  (1, 3, 4)    vert  2:5    horiz  6:9
Z[1,2,0,0]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  0:3
Z[1,2,0,1]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  0:3
Z[1,2,0,2]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  0:3
Z[1,2,0,3]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  0:3
Z[1,2,0,4]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  0:3
Z[1,2,0,5]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  0:3
Z[1,2,0,6]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  0:3
Z[1,2,0,7]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  0:3
Z[1,2,1,0]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  2:5
Z[1,2,1,1]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  2:5
Z[1,2,1,2]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  2:5
Z[1,2,1,3]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  2:5
Z[1,2,1,4]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  2:5
Z[1,2,1,5]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  2:5
Z[1,2,1,6]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  2:5
Z[1,2,1,7]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  2:5
Z[1,2,2,0]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  4:7
Z[1,2,2,1]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  4:7
Z[1,2,2,2]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  4:7
Z[1,2,2,3]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  4:7
Z[1,2,2,4]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  4:7
Z[1,2,2,5]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  4:7
Z[1,2,2,6]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  4:7
Z[1,2,2,7]      a_slice_prev.shape  (3, 3, 4)    vert  4:7    horiz  4:7
Z[1,2,3,0]      a_slice_prev.shape  (1, 3, 4)    vert  4:7    horiz  6:9
Z[1,2,3,1]      a_slice_prev.shape  (1, 3, 4)    vert  4:7    horiz  6:9
Z[1,2,3,2]      a_slice_prev.shape  (1, 3, 4)    vert  4:7    horiz  6:9
Z[1,2,3,3]      a_slice_prev.shape  (1, 3, 4)    vert  4:7    horiz  6:9
Z[1,2,3,4]      a_slice_prev.shape  (1, 3, 4)    vert  4:7    horiz  6:9
Z[1,2,3,5]      a_slice_prev.shape  (1, 3, 4)    vert  4:7    horiz  6:9
Z[1,2,3,6]      a_slice_prev.shape  (1, 3, 4)    vert  4:7    horiz  6:9
Z[1,2,3,7]      a_slice_prev.shape  (1, 3, 4)    vert  4:7    horiz  6:9
Z's mean =
 0.3519500704507587
Z[0,2,1] =
 [ -3.01280755  -2.90226517  -8.34171936  -5.26220853   5.6630696
   1.08704033   2.20430705 -10.73218294]
cache_conv[0][1][2][3] =
 [-1.1191154   1.9560789  -0.3264995  -1.34267579]
First Test: Z's mean is incorrect. Expected: 0.5511276474566768 
Your output: 0.3519500704507587 

First Test: Z[0,2,1] is incorrect. Expected: [-2.17796037, 8.07171329, -0.5772704, 3.36286738, 4.48113645, -2.89198428, 10.99288867, 3.03171932] 
Your output: [ -3.01280755  -2.90226517  -8.34171936  -5.26220853   5.6630696
   1.08704033   2.20430705 -10.73218294] 

InPut shape after padding with pad = 3:  (2, 11, 13, 4)
OutPut shape:  (2, 9, 11, 8)
Z[0,0,0,0]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  0:3
Z[0,0,0,1]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  0:3
Z[0,0,0,2]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  0:3
Z[0,0,0,3]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  0:3
Z[0,0,0,4]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  0:3
Z[0,0,0,5]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  0:3
Z[0,0,0,6]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  0:3
Z[0,0,0,7]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  0:3
Z[0,0,1,0]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  1:4
Z[0,0,1,1]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  1:4
Z[0,0,1,2]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  1:4
Z[0,0,1,3]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  1:4
Z[0,0,1,4]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  1:4
Z[0,0,1,5]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  1:4
Z[0,0,1,6]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  1:4
Z[0,0,1,7]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  1:4
Z[0,0,2,0]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  2:5
Z[0,0,2,1]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  2:5
Z[0,0,2,2]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  2:5
Z[0,0,2,3]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  2:5
Z[0,0,2,4]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  2:5
Z[0,0,2,5]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  2:5
Z[0,0,2,6]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  2:5
Z[0,0,2,7]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  2:5
Z[0,0,3,0]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  3:6
Z[0,0,3,1]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  3:6
Z[0,0,3,2]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  3:6
Z[0,0,3,3]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  3:6
Z[0,0,3,4]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  3:6
Z[0,0,3,5]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  3:6
Z[0,0,3,6]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  3:6
Z[0,0,3,7]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  3:6
Z[0,0,4,0]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  4:7
Z[0,0,4,1]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  4:7
Z[0,0,4,2]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  4:7
Z[0,0,4,3]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  4:7
Z[0,0,4,4]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  4:7
Z[0,0,4,5]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  4:7
Z[0,0,4,6]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  4:7
Z[0,0,4,7]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  4:7
Z[0,0,5,0]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  5:8
Z[0,0,5,1]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  5:8
Z[0,0,5,2]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  5:8
Z[0,0,5,3]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  5:8
Z[0,0,5,4]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  5:8
Z[0,0,5,5]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  5:8
Z[0,0,5,6]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  5:8
Z[0,0,5,7]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  5:8
Z[0,0,6,0]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  6:9
Z[0,0,6,1]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  6:9
Z[0,0,6,2]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  6:9
Z[0,0,6,3]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  6:9
Z[0,0,6,4]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  6:9
Z[0,0,6,5]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  6:9
Z[0,0,6,6]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  6:9
Z[0,0,6,7]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  6:9
Z[0,0,7,0]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  7:10
Z[0,0,7,1]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  7:10
Z[0,0,7,2]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  7:10
Z[0,0,7,3]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  7:10
Z[0,0,7,4]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  7:10
Z[0,0,7,5]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  7:10
Z[0,0,7,6]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  7:10
Z[0,0,7,7]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  7:10
Z[0,0,8,0]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  8:11
Z[0,0,8,1]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  8:11
Z[0,0,8,2]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  8:11
Z[0,0,8,3]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  8:11
Z[0,0,8,4]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  8:11
Z[0,0,8,5]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  8:11
Z[0,0,8,6]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  8:11
Z[0,0,8,7]      a_slice_prev.shape  (3, 3, 4)    vert  0:3    horiz  8:11
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-147-7e580406a9e8> in <module>
     15 
     16 conv_forward_test_1(z_mean, z_0_2_1, cache_0_1_2_3)
---> 17 conv_forward_test_2(conv_forward)

~/work/release/W1A1/public_tests.py in conv_forward_test_2(target)
     85     b = np.random.randn(1, 1, 1, 8)
     86 
---> 87     Z, cache_conv = target(A_prev, W, b, {"pad" : 3, "stride": 1})
     88     Z_shape = Z.shape
     89     assert Z_shape[0] == A_prev.shape[0], f"m is wrong. Current: {Z_shape[0]}.  Expected: {A_prev.shape[0]}"

<ipython-input-146-cd54402e1d74> in conv_forward(A_prev, W, b, hparameters)
     77                     weights = W[:,:,:,c]
     78                     biases = b[:,:,:,c]
---> 79                     Z[i, h, w, c] = conv_single_step(a_slice_prev,weights, biases)
     80                     print("Z[{},{},{},{}]     ".format(i, h, w, c), "a_slice_prev.shape ",
     81                           a_slice_prev.shape, "   vert ", "{}:{}".format(vert_start,vert_end),

<ipython-input-120-10297d0b0692> in conv_single_step(a_slice_prev, W, b)
     23     # Z = None
     24     # YOUR CODE STARTS HERE
---> 25     s = np.multiply(a_slice_prev,W)
     26     Z = np.sum(s)
     27     Z = Z + np.float64(b)

ValueError: operands could not be broadcast together with shapes (2,3,4) (3,3,4) 

Sorry, ignore my previous responses. I’m having a bit of trouble paging through your output and got confused.

How about this for a theory: maybe you have flipped the h and w dimensions? Notice that h stands for height, not horizontal. It is ok with vert 4:7 and horiz is also 4:7, but only goes bad when vert 4:7 and horiz goes to 6:9.

You did not say where in your code you are printing the shape of a_slice_prev.

The problem is likely in your conv_forward() function where you compute a_slice_prev.

The most likely causes for that is in the for-loops that compute the horiz and vert start and end.

Thank you, that was the problem. Sorry for the inconvenience that I caused, since I read this suggestion of yours in one of the threads, but I didn’t think that I would get this part wrong so I did not try it. and what made me sure is that I did a few steps by hand and it agreed with the expected output.

It’s good news that you found the issue! Thanks for confirming.