W2_A2_Ex-8_Shape not aligned

Hi, Can anybody explain this value error to me? Thank You

Hello Hamza!

You are initializing the w with the wrong shape. Check out that you implemented the Ex. 4 initialize_with_zeros correctly. If you are sure that it is correct, then check that you call it with the correct argument in both Ex. 4 and Ex. 8 model.

Furthermore, you can add the below code in your model function, just after you initialize the w and b.

print(f"w shape is {w.shape}")
print(f"X_train shape is {X_train.shape}")

My output is:
w shape is (4, 1)
X_train shape is (4, 7)

Also, read this thread which discusses a similar topic.

Best,
Saif.

Well, I’ve checked Exercise 4, and my code is right. In exercise 8, I am calling the function using “dim” which gives a different value, and because of it, I am getting an error. Now, I know I don’t have to use the global variable “dim”, but I don’t understand which local variable I should use to call the function.

Hi @Syed_Hamza_Tehseen ,

The dim should be taken from your training data, not a global variable, because your model can be given a different training dataset. So you need to extract the dim from the input argument of model(), which is X_train. Once you got the dim from the X_train, you can then pass that to initialize_with_zeros().

How do I get the “dim” from “X_train”?

What is the meaning of the dim argument that is passed to initialize_with_zeros? It is the number of “features” in each input vector, right? So how can you determine that from the shape of the input “samples” matrix X_train, given that each column of X_train is one input sample vector?

I’ve used "X_train.shape[0] " as an argument and it haas given me the right answer. But now, I’m facing this assertion error

That means you have hard-coded the number of iterations when you call optimize from model. Are you familiar with how “keyword” parameters work in python? If not, try googling “python keyword parameters” and spend some time reading up on them.

Yes, I’ve got it now. Thank you all so much for your help. Much appreciated