Assignment question 2 help

This is the error message, what should I do?

Wrong size of the input layer n_x for the test case, where array X has a shape (5, 100).
Expected: 5.
Got: 1.
Wrong size of the output layer n_y for the test case, where array Y has a shape (3, 100).
Expected: 3.
Got: 1.
2 Tests passed
2 Tests failed

Hi @Mahad_Kamran ,

I have not done your course, but this is what I know:

If X has a shape of (5,100), it means that there are 5 input features and 100 examples, so n_x should be 5
if Y has a shape of (3,100), it means that there 3 output classes and there are 100 examples, so n_y is 3

If in doubt, revisit the lecture video on the subject really helps.

@Mahad_Kamran, which function is throwing this error?

It would help if you post a screen capture image that shows the entire error or assert message.


Hi @Mahad_Kamran ,

You have hard-coded the input and output layer in the layer_sizes() function. Please refer to my previous reply showing you where n_x and n_y come from.

At the start of the layer_sizes() function, the comment text explaining what the input arguments X, Y are. So to get n_x, you need to extract the input_size from X, and likewise, for n_y, take the output size from Y .

Hint: Use the “shape” function.

Hi @Mahad_Kamran ,

The input arguments X, Y are explained in details at the start of this function. To extract the size of the input/output layer, we use the “shape” function associated with X and Y. Here is how to do it:

n_x= X.shape[0] - selecting the input size element of X
n_y=Y.shape[0] - selecting the output size element of Y

Once you have this function working correctly, the initialize_parameters() function should work fine.