Course 4 Week1 Programming Assignment Conv_forward

I am getting the following error message:

Z's mean =
 0.3519500616419224
Z[0,2,1] =
 [-2.17796092  8.07171371 -0.5772704   3.36286715  4.48113637 -2.8919842
 10.99288881  3.03171899]
cache_conv[0][1][2][3] =
 [-1.1191154   1.9560789  -0.3264995  -1.34267579]

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-8-182241fd5e53> in <module>
     11 print("cache_conv[0][1][2][3] =\n", cache_conv[0][1][2][3])
     12 
---> 13 conv_forward_test(conv_forward)

~/work/release/W1A1/public_tests.py in conv_forward_test(target)
     65     b = np.random.randn(1, 1, 1, 8)
     66 
---> 67     Z, cache_conv = target(A_prev, W, b, {"pad" : 3, "stride": 1})
     68     Z_shape = Z.shape
     69     assert Z_shape[0] == A_prev.shape[0], f"m is wrong. Current: {Z_shape[0]}.  Expected: {A_prev.shape[0]}"

<ipython-input-7-a0f4009e0100> in conv_forward(A_prev, W, b, hparameters)
     80                     weights=W[:, :,:,c]
     81                     biases=b[:,:,:,c]
---> 82                     Z[i,h,w,c]=conv_single_step(a_slice_prev, weights, biases)
     83 
     84 

<ipython-input-5-6280408d5a44> 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, dtype=np.float32)
     26     Z=np.sum(S)
     27     Z=Z+np.float(b)

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


I have spent a considerable amount of time to figure out the issue but failed. I would greatly appreciate any sort of help. Thank You.

I always recommend a search before posting in case another student has had the same problem:

Thank you for your response.

Edited: The problem has been resolved, it seems I was looping over the wrong variable.

Sorry for your inconvenience

1 Like