Index error Week 4, Ex 1 - L_model_backward

I have cleared the assignment with “80%”, but I cannot get through the L_model_backward .

  1. The error now received is this:

IndexError Traceback (most recent call last)
in
1 t_AL, t_Y_assess, t_caches = L_model_backward_test_case()
----> 2 grads = L_model_backward(t_AL, t_Y_assess, t_caches)
3
4 print("dA0 = " + str(grads[‘dA0’]))
5 print("dA1 = " + str(grads[‘dA1’]))

in L_model_backward(AL, Y, caches)
58 # YOUR CODE STARTS HERE
59 current_cache=caches[l-1]
—> 60 dA_prev_temp, dW_temp, db_temp = linear_activation_backward(grads[“dA”+str(l+1)], current_cache, “relu”)
61 grads[“dA” + str(l)] = dA_prev_temp
62 grads[“dW” + str(l+1)] = dW_temp

in linear_activation_backward(dA, cache, activation)
22 # dA_prev, dW, db = …
23 # YOUR CODE STARTS HERE
—> 24 dZ=relu_backward(dA,activation_cache)
25 dA_prev,dW,db=linear_backward(dZ,linear_cache)
26 # YOUR CODE ENDS HERE

~/work/release/W4A1/dnn_utils.py in relu_backward(dA, cache)
54
55 # When z <= 0, you should set dz to 0 as well.
—> 56 dZ[Z <= 0] = 0
57
58 assert (dZ.shape == Z.shape)

IndexError: boolean index did not match indexed array along dimension 0; dimension is 3 but corresponding boolean dimension is 1

The lines: 55 # When z <= 0, you should set dz to 0 as well.
—> 56 dZ[Z <= 0] = 0.
I should go back to linear_activation_backward, where the value of Z comes from activation_cache, and put in a condition that dz = 0 if z<=0?
I did try, but it does not help.
2. Request help, or a resource where I can better understand the L_model_backwar.

Hi @Anantha,

Can you share your lab ID with me ? In the assignment, when you click the top right “Help” button, a panel will open and your lab ID will be shown at the bottom.

I shall take a look.

When you reply back, kindly tag me in the post so that I’m notified.

Thanks,
Mubsi