Update Parameters in Building NN Step-by-Step Lab

Hello
In the last graded cell of this lab Building_your_Deep_Neural_Network_Step_by_Step,
in the
def update_parameters(params, grads, learning_rate): function,
this line of provided code

parameters = params.copy()

seems to be wrong. It creates a shallow copy of params, whereas a deep copy needs to be created - correct?
This shallow copy doesn’t work for me, but a deep copy did. Am I doing something wrong?
thanks!

You are correct that a deep copy is necessary there. Either that or you just need not to use the -= “in place” operator, in which case no copy would be necessary.

Here’s a thread which discusses these points in more detail, but it sounds like you probably already understand the points being mentioned there if you figured out the “deepcopy” solution.

I’ll file a suggestion with the course staff that they should change the template code for that function.

1 Like

Thank you. Yes, i understand object references in Python and copy vs deepcopy. But i didn’t realize that W1 -= … and W1 = W1 - … worked differently. I made the -= work by doing the deepcopy but it took me a long time to get to that point.
Thank you for explaining this subtle difference. A nasty surprise indeed :slightly_smiling_face: