Prog assignment Ex 3: operands could not be broadcast together

Hi,

I’m having trouble with the dimensions in Exercise 3 of week 1’s programming assignment.

The looping over a_prev_pad seems to go well for a while, but then the shape of the weights shrink to (3,2) causing a ValueError.

I can’t figure out what goes wrong. Help is appreciated.

My output is:
shape a_prev_pad = (7, 9, 4)
shape a_slice_prev = (3, 3)
shape weights = (3, 3)
shape biases = ()
s =
[[ 0. -0. -0. ]
[ 0. 0.71208934 1.242098 ]
[-0. -0.90125087 1.24799909]]
Z =
2.3009355649211543
shape a_slice_prev = (3, 3)
shape weights = (3, 3)
shape biases = ()
s =
[[-0. -0. -0. ]
[-0. -0.36621645 0.22399368]
[-0. 0.19079189 0.09611959]]
Z =
0.14468871309136205
shape a_slice_prev = (3, 3)
shape weights = (3, 3)
shape biases = ()
s =
[[-0. 0. 0. ]
[ 0. 0.81338246 -1.34004019]
[ 0. -0.48759246 -0.01308233]]
Z =
-1.0273325173618622
shape a_slice_prev = (3, 3)
shape weights = (3, 3)
shape biases = ()
s =
[[-0. -0. -0. ]
[ 0.71208934 1.242098 -0.35142605]
[-0.90125087 1.24799909 -0.03275062]]
Z =
1.9167588952880614
shape a_slice_prev = (3, 3)
shape weights = (3, 3)
shape biases = ()
s =
[[-0. -0. -0. ]
[-0.36621645 0.22399368 2.36994872]
[ 0.19079189 0.09611959 2.30100743]]
Z =
4.815644865107138
shape a_slice_prev = (3, 3)
shape weights = (3, 3)
shape biases = ()
s =
[[ 0. 0. -0. ]
[ 0.81338246 -1.34004019 1.66085416]
[-0.48759246 -0.01308233 0.40673636]]
Z =
1.0402580018637435
shape a_slice_prev = (3, 3)
shape weights = (3, 2)
shape biases = ()

ValueError 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)
82 print("shape weights = ", weights.shape)
83 print("shape biases = ", biases.shape)
—> 84 Z[i, h, w, c] = conv_single_step(a_slice_prev, weights, biases)
85 # YOUR CODE STARTS HERE
86

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 print(“s = \n”, s)
27 Z = np.sum(s)

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

1 Like

Please check this guide which explains everything of this exercise.

1 Like

Ah, maybe I found it. Should the indices of W be fixed instead ranging from vert_start to vert_end and horiz_start to horiz_end?

1 Like

The last dimension of W should change with the channel loop. Do you understand the below point?

1 Like