C2W2 programming assignment "Optimization Methods"

The code you show looks fine and is independent of the layer number. So if you get the correct results for layer 1, but not layer 2, the bug must be elsewhere. E.g. maybe your loop indices are wrong or something else like that which would affect only some layers …

Ok, you can’t modify the test cell, but I used “Insert → Cell Below” and added this code to find out what the original value of W2 is before the “update”:

parameters, grads, learning_rate = update_parameters_with_gd_test_case()
print("W2 =\n" + str(parameters["W2"]))

Here’s the output I get:

W2 =
[[ 0.3190391  -0.24937038  1.46210794]
 [-2.06014071 -0.3224172  -0.38405435]
 [ 1.13376944 -1.09989127 -0.17242821]]

Notice that is the same as your incorrect value of W2. So you must have modified the template code of the “for” loop and broken it so that it no longer covers layer 2.

If you want to get a clean copy of the notebook and see what the template code originally looked like, there’s a topic about that on the FAQ Thread. It’s not illegal to modify the template code, but it requires extreme care.