Exercise 8 - model

I need to identify where below error is coming from (I get it after running model_test(model) )
ValueError: shapes (1,2) and (4,7) not aligned: 2 (dim 1) != 4 (dim 0)

Hi @Alex_Cotarlan ,

The Week 1 of this course does not have a Code Assignment. So I guess, you are asking about the second Code Assignment of Week 2 (C1W2_Assignment_2), which does have “Exercise 8 - model”. According to one of the description lines of this exercise: “Predict test/train set examples (≈ 2 lines of code)”, you need to use the function from the “Exercise 7 - predict”, which has a subtask: image. and for the image, which is a dot product, there is a constraint on dimensions (shapes) of the components (arrays): (M, N) · (N,P) ➔ (M,P), but your error message tells you, that your “Ns” are not equal: it’s 2 for one of the arrays, and 4 – for another. Also the shape of b should be consistent with the shape of the dot product and the Python’s (numpy) broadcasting compatibility rules. So please, check the shapes of all parameters (numpy arrays) which you send/use in your predict function of the “Exercise 8 - model”.

Best regards,

Dmitry.

Hi, Alex.

I added some print statements to my model code to show the shapes of all the objects and here’s what I see when I run model_test:

Notice that X is 4 x 7 and w is 4 x 1, so that when you do the dot product to compute Z the inner dimensions match:

Z = w^T \cdot X + b

It looks like in your code the dimensions of w turn out to be 2 x 1. So how could that happen? Where are those dimensions determined? By the arguments you pass when you call the initialization routine, right?