Accessing values in a dictionary requires brackets []
, not parentheses ()
(see this answer. From the code you’ve given us, it looks like grads("db" + str(l+1))
needs to be changed to grads["db" + str(l+1)]
to fix your error.
A few notes on style:
- The character lowercase ‘
l
‘ shouldn’t be used as a variable name in order to avoid confusion with capitalI
or the number1
. - The
a = a - b
pattern can be replaced witha -= b
. - Since
str(l+1)
is called so frequently, you might consider saving that string as a variable.
solved Updating dictionary in python, during gradient descent