Logistic_Regression_with_a_Neural_Network_mindset_Week2

Hi,

I am getting the following error for Exercise-4 (Initialize with Zeros

AssertionError Traceback (most recent call last)
in
6 print ("b = " + str(b))
7
----> 8 initialize_with_zeros_test_1(initialize_with_zeros)
9 initialize_with_zeros_test_2(initialize_with_zeros)

~/work/release/W2A2/public_tests.py in initialize_with_zeros_test_1(target)
19 assert b == 0., β€œb must be 0.0”
20 assert type(w) == np.ndarray, f"Wrong type for w. {type(w)} != np.ndarray"
β€”> 21 assert w.shape == (dim, 1), f"Wrong shape for w. {w.shape} != {(dim, 1)}"
22 assert np.allclose(w, [[0.], [0.], [0.]]), f"Wrong values for w. {w} != {[[0.], [0.], [0.]]}"
23 print(β€˜\033[92mFirst test passed!’)

AssertionError: Wrong shape for w. (3,) != (3, 1)

Not sure, where I am going wrong.
Can someone please help?

Regards
Ravikiran

Hello, Ravikiran @ravivemuri ,

When an error happens, we can first read the last line:

Then go up to read the first line with an arrow pointed to it:

Then we see how that error message was generated.

The message says the shape does not match with expectation, but which one is the expected and which is given to it? If we compare with the arrowed line, we can guess that (3, 1) is the expected one and w.shape, which is (3, ) is the given one because w is being checked and that w is produced by the function completed by you.

Now if you look at the exercise again, and check the function’s docstring, you can find this:

    Returns:
    w -- initialized vector of shape (dim, 1)

which has explicitly requires your w to have the shape of (dim, 1). See? Two numbers in the shape, not just one.

So, now the thing is how you are going to use np.zeros to produce an array that is 2 dimensional, because only a 2 dimensional array has 2 numbers in its shape. Your current w is 1 dimensional because it only has 1 number in its shape. However, for this one, I have to leave it to you because that is the exercise you need to complete, but you can google for the documentation of np.zeros to find out how to use it.

Good luck!

Cheers,
Raymond

1 Like

Thank You, Raymond,

I figured out that I missed passing the size and the explicit data type.
Now it worked.

Regards
Ravikiran

1 Like

You are welcome, Ravikiran!

Cheers,
Raymond