C1, Wk4, Ex10 update parameters. Datatype traceback

Hi there.

I am getting a traceback that, if I am interpreting it correctly, seems to be telling me that something in the ‘grads’ dictionary of arrays is a string rather than a float.

I enclose the ‘grads’ printout, which shows arrays composed of floats, as is to be expected, as well as the traceback.

Please advise

Well take a more careful look at what is on the right hand side of the assignment statement that is throwing the error. The first term in that subtraction is a string, right? It will be “W2” or whichever layer you are processing. That is what is causing the error. The first step in debugging is you need to believe what the error message is telling you. There is something wrong with the subtract operation in that the two operands are not of compatible types. So look at the operands. What types are they? Why are they not compatible? Hint: the problem has nothing to do with the grads dictionary.

Also why do you need to use np.dot in the second term there? learning_rate is a scalar, right? Mind you, that won’t throw an error, but it’s just more work than you need to do.

Thanks for that Paul.

I think I am almost there and I’ll keep at it.
I have revised most of the right hand side, but may I just ask one further question.

If I hard code ‘dW1’, I get W1 and b1 right and pass the first test. Obviously W2 and b2 are wrong because they are using the W1 matrix dimensions. If I use a “parameters [“Wl”]” or[“Wl+1”]" term, it throws a KeyError: ‘Wl+1’ alert, which presumably means it doesn’t recognise the ‘Wl’ term.

Am I now just looking for the right term to update the parameters and grads for W2 and b2 without hard coding them?

I have enclosed the traceback in case the answer to my question is ‘No’.

They gave you the correct method in the template code. Look at the left hand side of those assignment statements. You need to use the str() function in python to concatenate the layer number onto the base of the string name.

All tests passed.

Thank you Paul.

I now understand that I misinterpreted your first comments and (wrongly) took out the ‘str()’ terms.

Hindsight. Its a useful thing.

Many thanks