C4 W1 exercise 3 name 'c' is not defined

Hi, thanks for help! I am working on exercise 3, and face a problem when using vectorization instead of for loop.
parts of my code are:
vert_start = n_Hstride
horiz_start = n_W
stride
horiz_end = horiz_start+f

weights = W[:,:,:,c]
biases = b[:,:,:,c]

There is an error as shown below:
----> 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)
75 horiz_end = horiz_start+f
76 a_slice_prev = A_prev_pad[vert_start:vert_end,horiz_start:horiz_end,:]
—> 77 weights = W[:,:,:,c]
78 biases = b[:,:,:,c]
79 Z[i, h, w, c] = conv_single_step(a_slice_prev,weights,biases)

NameError: name ‘c’ is not defined

I tried to using n_C instead of c, but another error happens:

in conv_forward(A_prev, W, b, hparameters)
75 horiz_end = horiz_start+f
76 a_slice_prev = A_prev_pad[vert_start:vert_end,horiz_start:horiz_end,:]
—> 77 weights = W[:,:,:,n_C]
78 biases = b[:,:,:,n_C]
79 Z[i, h, w, c] = conv_single_step(a_slice_prev,weights,biases)

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

What shoud I do ? Can anyone help me ? Thanks again!

If you are using 4 loops and c is the variable in the inner most loop, please click my name and message your notebook as an attachment.

# for c in range(None):   # loop over channels (= #filters) of the output volume

Now I change my codes using four loops, but there are still error:

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 weights = W[:,:,:,c]
83 biases = b[0,0,0,c]
—> 84 Z[i, h, w, c] = conv_single_step(a_slice_prev,weights,biases)
85 # YOUR CODE ENDS 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 Z=np.sum(s)
27 #Z=Z+np.float(b)

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

Sounds like you have some debugging to do. Your shapes are wrong. So how did that happen? Which are the correct ones? It looks like you are managing the A_prev values and the slicing of them incorrectly. For starters in the inner loop, you’ve already selected one sample (the first dimension), so the A value should have only 3 dimensions, right? So that’s the first thing to figure out. As usual, they give you lots of helpful hints in the comments. You may think you are saving yourself time by not reading them carefully but that usually ends up being a false economy. :nerd_face: