Course 1 Week 4 Assignment 1 Exercise 9 KeyError: 'dA1'

There is an error in my code. It shows that:

KeyError Traceback (most recent call last)
4 print("dA0 = " + str(grads[‘dA0’]))
----> 5 print("dA1 = " + str(grads[‘dA1’]))
6 print("dW1 = " + str(grads[‘dW1’]))
7 print("dW2 = " + str(grads[‘dW2’]))

KeyError: ‘dA1’

Does anyone know what is the problem?

Your code returns a grads dictionary that does not contain the key ‘dA1’. Why it does that, I can’t say. That’s your job to figure out. Try adding some print statements to your code to show each time you add an element to the grads dictionary. Perhaps there is something wrong with your loop logic.

Please realize that every student’s notebooks are private to their account, so no-one else can just magically reach in and debug your code for you.

Hello @samuelcesarino
Try printing the grads ‘keys’. And then you will figure out why ‘dA1’ is missing.
Then recheck the line where you are adding keys & values into the grads dictionary.

All the best

1 Like