Hi,
I need help in debugging the following error I am getting in Exercise 9 of Week 4 assignment of course 1.
IndexError: boolean index did not match indexed array along dimension 0; dimension is 1 but corresponding boolean dimension is 3
It seems the error is happening because of shape of Z is not matching the shape of dZ and I am not sure why that should happen if all previous tests have passed. Secondly, I do not see any issue in how I am getting grads in this helper function, so completely clueless now. I have been trying to debug this code for complete 2 days now so request for some help please
Just because the error is thrown in code you did not write does not mean it’s not your fault: what it means is that your higher level code passed mismatching arguments down to the lower level function. You can examine the code in relu_backward to understand how it works. Just click “File → Open” and then open the file dnn_utils.py.
So either the dA value or the activation_cache value must be wrong. Note that you are passing dAL as the dA argument. That only works for the output layer, right?
1 Like
In particular, note that the contents of the activation_cache is Z. And dA is the same shape as A, which in turn is the same shape as Z, right? So why is that not true in your case? Try printing the shapes in your linear_activation_backward function and then work backwards to figure out why they don’t match.
Hi Paulin
Thanks a ton! I was passing dAL instead of dA value and now it’s working. What a glaring bad eye for detail! But I still do not understand your 2nd comment. Shape of Z = shape of dZ = shape of A = shape of dA, but can you help me understand how you interpret shape of A is not equal of shape of Z or dZ from the error. Thank you.
Did you look at the code in relu_backward? It should become clear if you examine that. That’s what I meant as the high level point about how debugging works. You have to start from the actual point of the error and understand what it means. Then you work backwards one step at a time.
The original error message tells you that dZ and Z do not have the same shape. So then you have to look at the relu_backward code to see where the dZ and Z values come from.