Got error in the code - python changed its random generator?

{moderator edit - solution code removed}

np.random.seed(2)
n_x, n_h, n_y = initialize_parameters_test_case()
parameters = initialize_parameters(n_x, n_h, n_y)

print("W1 = " + str(parameters[“W1”]))
print("b1 = " + str(parameters[“b1”]))
print("W2 = " + str(parameters[“W2”]))
print("b2 = " + str(parameters[“b2”]))

initialize_parameters_test(initialize_parameters)

--------------got this error---------------------
W1 = [[0.00435995 0.00025926]
[0.00549662 0.00435322]
[0.00420368 0.00330335]
[0.00204649 0.00619271]]
b1 = [[0.]
[0.]
[0.]
[0.]]
W2 = [[0.00299655 0.00266827 0.00621134 0.00529142]]
b2 = [[0.]]

AssertionError Traceback (most recent call last)
in
8 print("b2 = " + str(parameters[“b2”]))
9
—> 10 initialize_parameters_test(initialize_parameters)

~/work/release/W3A1/public_tests.py in initialize_parameters_test(target)
57 assert parameters[“b2”].shape == expected_output[“b2”].shape, f"Wrong shape for b2."
58
—> 59 assert np.allclose(parameters[“W1”], expected_output[“W1”]), “Wrong values for W1”
60 assert np.allclose(parameters[“b1”], expected_output[“b1”]), “Wrong values for b1”
61 assert np.allclose(parameters[“W2”], expected_output[“W2”]), “Wrong values for W2”

AssertionError: Wrong values for W1

No, the problem is you used the wrong random function. The clue is that all your output values are positive. That would not be true if you used a normal distribution with \mu = 0 and \sigma = 1. Please have a more careful look at the instructions. They basically wrote the code out for you in the instructions.

Thanks a lot for your quick reply. I did not notice we need to use normal. That helps

1 Like