Course 1 Week 3 exercise 7

If you are copying the parameters individually as you are doing, the deepcopy is not necessary: a simple copy will work. But if you want to copy the whole dictionary in one shot (it’s less code), then you need the deepcopy. This is explained on this thread. Please read all the way through. The deepcopy is explained later in the thread.

The summary is that “deep” copy is necessary when the object you are copying itself contains object references. The “deep” copy goes through depthwise and makes new copies of everything. If you do “simple” copy, it just copies the top level object. In your example above, W1 is just a numpy array, so it’s a python object, but it doesn’t reference any other objects. That’s why a simple copy is all that is required in that case.

1 Like