Unit test in exercise 2 "initialize_parameters_test" not matching random.seed(2)

I dont think the numbers in the unit test “initialize_parameters_test” match the numbers generated by np.random.seed(2) . Are you sure this unit test is correct?

def initialize_parameters_test(target):
np.random.seed(2)
n_x, n_h, n_y = 3, 5, 2

expected_output = {'W1': np.array(
    [[-0.00416758, -0.00056267, -0.02136196],
     [ 0.01640271, -0.01793436, -0.00841747],
     [ 0.00502881, -0.01245288, -0.01057952],
     [-0.00909008,  0.00551454,  0.02292208],
     [ 0.00041539, -0.01117925,  0.00539058]]), 
                   'b1': np.array([[0.], [0.], [0.], [0.], [0.]]), 
                   'W2': np.array([[-5.96159700e-03, -1.91304965e-04,  1.17500122e-02,
    -7.47870949e-03,  9.02525097e-05],
   [-8.78107893e-03, -1.56434170e-03,  2.56570452e-03,
    -9.88779049e-03, -3.38821966e-03]]), 
                   'b2': np.array([[0.], [0.]])}

Setting the seed value to 2 ensures that every time you run the code, you will get the same set of random numbers.

do you get the same random numbers which are hard coded in the unit test example though when using seed 2?

Yes, that is the idea.

sorry, i just cant get this unit test to pass.

np.random.seed(2)
W1=np.random.rand(5,3)*0.01

gives:
array([[0.00435995, 0.00025926, 0.00549662],
[0.00435322, 0.00420368, 0.00330335],
[0.00204649, 0.00619271, 0.00299655],
[0.00266827, 0.00621134, 0.00529142],
[0.0013458 , 0.00513578, 0.0018444 ]])

which is not the same as the hard coded values in the unit test. what have i done wrong?

Share your full error.

ah this is my error - in the example i gave above i used the incorrect random function.

i used np.random.rand and not np.random.randn

Glad to know that you solved it on your own.