Wrong shape for W1 in course 1 week 3 exercise 3

Hello Team,

In the course 1 week 3 exercise 3 i get the following 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.]]

which is matched with the Expected output but i got the error
Wrong shape for W1.

My code snippet is as follows

{moderator edit - solution code removed}

please help.
Thanks in advance.

@Abhay25 I think your mistake is you are ‘hard coding’ the layer sizes.

Consider what variables you have coming into the function and ensure your solution is general.

4 Likes

Thank you very much.
It resolves the issue. :slight_smile:

1 Like

Its amazing :star_struck:

In the previous question we have been calculated (input layer)n_x =5
and the now parameter(n_x) when given to function is n_x=2 .
could anyone support why the n_x value changed ?
PFB Function and their parameteres
def initialize_parameters(n_x, n_h, n_y):

Your code is a general-purpose tool. It should work with any number of units in each layer.

Salam Alykum TMosh ,
Please find below 2 snap ,First Pic n_x=5 but when we are continue the task in the next question the n_x=2 ?how can we continue the whole task if parameters is not fixed .


In your code in the initialize_parameters() function, you should use the variables n_x, n_h, and n_y. Do not use any fixed constant values.

I know that, but in the previous function called :(def layer_sizes(X, Y):slight_smile:
n_x=5, So can you please tell me what 's the benefits of value changing for n_x=2 in the initialize_parametes(x,h,y).
why we are not keep n_x=5 for all the previous and current function as the same.
Thank you for your fast reply ,Appreciated .

You are referring to this?

This is an example of setting the number of input and output units based on the shapes of the data set.

But this does not work for setting the number of hidden layer units, because that is a design decision that does not depend on the X inputs or the Y outputs.

1 Like

Thank you for responding but i have crucial question how can we calculate Hidden layer count in real dataset? please check function
inside Exercise 3 initialize_parameters
n_x, n_h, n_y = initialize parameters test_case()
also give us n_h=4 ,
how can be n_h=4 for both exercise and they mentioned that will be applied only in the excercie 2 ?

You can’t calculate the number of hidden layer units from the dataset.

This is because the dataset only gives the inputs to the first first layer, and the labels from the output layer.

The number of hidden layer units is a design decision that you make as the machine learning engineer. You select the number of hidden layer units such that you get “good enough” performance.

1 Like

I got you, Thank you at least i learned something from these questions .
Thanks

1 Like