Exercise 9 - L_model_backward --

I’m getting this error

 58     assert (dZ.shape == Z.shape)

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

grads = {}
L = len(caches) # the number of layers
m = AL.shape[1]
Y = Y.reshape(AL.shape) # after this line, Y is the same shape as AL

(Moderator edit: code removed)

Hi @Jefferson_Fernandez, you are missing the ‘grads’ while calling the function for linear activation backward in reverse order for (l).
Also, did you hard-coded any of the values?


Hi, @Jefferson_Fernandez. As a reminder, it is against the course code of conduct to post your code in the course Discourse forum, or any other public outlet. You are instead permitted (and encouraged!) to post the “traceback” (i.e. the error log) which details the errors produced through the “call stack.” Functions usually rely on other functions and so this is quite necessary to debug your code.

That said, it looks like @Rashmi took a peek and may have noticed that you were not retrieving your dA's from the grads dictionary which is populated further up in the L_model_backward function. It is the first argument in the call to the linear_activation_backward function. Which illustrates the point that a careful study of the traceback is typically essential for debugging and, on top of that, will make you a better programmer! :smiley: