Get wrong W1, this is my code…
Can anyone help?
The code seems fine, but you are not allowed to post this publicly!
What are you getting as the output after the test code?
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
Expected output
W1 = [[-0.00416758 -0.00056267]
[-0.02136196 0.01640271]
[-0.01793436 -0.00841747]
[ 0.00502881 -0.01245288]]
b1 = [[0.]
[0.]
[0.]
[0.]]
W2 = [[-0.01057952 -0.00909008 0.00551454 0.02292208]]
b2 = [[0.]]
All tests passed!
Hi @yuvalbz ,
Please check that you are using np.random.randn() to generate W1, and W2
You are right, I was using np.random.random() because when I was using np.random.randn(), I got the following output:
TypeError Traceback (most recent call last)
in
1 np.random.seed(2)
2 n_x, n_h, n_y = initialize_parameters_test_case()
----> 3 parameters = initialize_parameters(n_x, n_h, n_y)
4
5 print("W1 = " + str(parameters[“W1”]))
in initialize_parameters(n_x, n_h, n_y)
21 # b2 = …
22 # YOUR CODE STARTS HERE
—> 23 W1 = 0.01 *np.random.randn((n_h,n_x))
24 b1 = np.zeros((n_h,1))
25 W2 = 0.01 *np.random.randn((n_y,n_h))
mtrand.pyx in numpy.random.mtrand.RandomState.randn()
mtrand.pyx in numpy.random.mtrand.RandomState.standard_normal()
_common.pyx in numpy.random._common.cont()
TypeError: ‘tuple’ object cannot be interpreted as an integer
Hi @yuvalbz,
The problem lies in the way you passed in the parameters to np.random.randn(), which is tuple, W1 = 0.01 *np.random.randn((n_h,n_x)). This function expects parameters as int, not tuple. There should only be one set of (), like this: W1 = 0.01 *np.random.randn(n_h,n_x).
Here is an extract from the reference menu:
random.randn(d0 , d1 , … , dn )
Parameters:
d0, d1, …, dn int, optional
The dimensions of the returned array, must be non-negative. If no argument is given a single Python float is returned.
Thanks a lot
This was very helpful:-)