Week 4 In 93 def initialize_parameters(n_x, n_h, n_y)

I fail in In 93 def initialize_parameters(n_x, n_h, n_y)

def initialize_parameters(n_x, n_h, n_y):
“”"
Argument:
n_x – size of the input layer
n_h – size of the hidden layer
n_y – size of the output layer

Returns:
parameters -- python dictionary containing your parameters:
                W1 -- weight matrix of shape (n_h, n_x)
                b1 -- bias vector of shape (n_h, 1)
                W2 -- weight matrix of shape (n_y, n_h)
                b2 -- bias vector of shape (n_y, 1)
"""
np.random.seed(1)

#(≈ 4 lines of code)
# W1 = ...
# b1 = ...
# W2 = ...
# b2 = ...
# YOUR CODE STARTS HERE
W1 = np.random.rand(n_h, n_x)*0.01
#print("Mark 1 W1="+str(W1))
b1 = np.zeros([n_h, 1])
W2 = np.random.rand(n_y, n_h)*0.01
#print("Mark 2 W2="+str(W2))
b2 = np.zeros([n_y, 1])
# YOUR CODE ENDS HERE
parameters = {"W1": W1,
              "b1": b1,
              "W2": W2,
              "b2": b2}

return parameters    



The output is this.

Test Case 1:

W1 = [[4.17022005e-03 7.20324493e-03 1.14374817e-06]
 [3.02332573e-03 1.46755891e-03 9.23385948e-04]]
b1 = [[0.]
 [0.]]
W2 = [[0.0018626  0.00345561]]
b2 = [[0.]]
Error: Wrong output for variable W1.
Error: Wrong output for variable W2.
 1  Tests passed
 1  Tests failed

Hi @vcychan ,

To generate the weights, you need to use np.random.randn as specified in the instructions.

Please post your query in the forum specific for your course for speedy response.

1 Like

What course are you attending? You did not mention this, nor did you post your message in the forum for any course.

W2 = np.random.rand(n_y, n_h)*0.01

The error were shown.

Error: Wrong output for variable W1.
Error: Wrong output for variable W2.
1 Tests passed
1 Tests failed

I studying the Deep Learning course. Can you give me the forum URL?

You can find it in the “Course Q&A” topic, in the left-side menu.

Hi @vcychan ,

The instructions for this exercise specified to use np.random.randn, which is different from the function you used. It is important to read the instructions for correct implementation. Otherwise, your code would not give the output as expected. This is what happened in your case.