I do not understand why even though I have passed my previous tests, I cannot retrieve data from parameters
using string.
Thank you for all of your assistances throughout the course
I do not understand why even though I have passed my previous tests, I cannot retrieve data from parameters
using string.
Thank you for all of your assistances throughout the course
The error message is pretty clear, isn’t it? It’s because the data type of the parameters variable there is wrong: it is a tuple, but it should be dictionary. You can verify this by putting this print statement right before the line that “throws”:
print(type(parameters))
Now the question is why that happened. Time for some more careful examination of where that value is assigned. My guess is that the error probably happens the second time through the loop because you are getting parameters as the return value from a function, but the function actually returns several values. In python, if you have a function that returns multiple values, but you invoke it like this with a single variable to hold the return values:
answer = myFunction(myArgs)
Then python tries to “help you out” in a way you might not expect from other languages like MATLAB: it packages up all the return values into a tuple and assigns that to answer. If you did that in MATLAB, it would just give you the first of the return values and discard the rest, but not in python.
Although looking at the code, the most likely case is the call to update_parameters in nn_model, but that only returns one value. So maybe my theory there is not applicable. Well, unless you modified the return statement in update_parameters, but then the test for update_parameters should have failed. More investigation required …
This is the way debugging works, right? You have to start from the error message at the point of the failure. The first step is to really understand what it is telling you. Of course the line where the error happens is probably not where the real mistake is and you then have to track backwards to figure out where the actual problem is. So the next step here is to follow the control flow and find the last place that parameters was assigned a value.
OMG, I forgot to call the function update_parameters
and just said
parameters = (parameters, grads)
. That fixed everything.
That would explain it!