Week2 Programming Assignment: Logistic Regression with a Neural Network Mindset EX5

I wrote codes and I could get correct values but I can’t get okay.
First picture is results and error message. I can understand what error message is saying but I’m not
sure what is wrong

Second picture is probably wrong part of code.

(Solution code removed, as posting it publicly is against the honour code of this community)

I would like to fix this problem. Please .
Best regards.

Hi @Koyo_Fujii,

Firstly, please refrain from publicly posting solution code, as doing so is against the honour code of the community. You are allowed to post about your errors, and if the mentors believe they need to look at your code, they’ll direct message you.

As your error traceback is telling you, you have the issue occurring in the line where you are initialising A.

The error tells you about the mismatch between the matrices, and that is because you are adding a matrix of b’s of shape (1, 3), which is wrong. You need to add just b. As you have learned in the Course so far, Python takes care of the broadcasting itself whenever it can.

Hope this helps,

Thank you for replying to me, and I’m so sorry .
I’ll keep it that in my mind.

Even though I use just b, I get the same error message.
In addition to that, I have two things to ask you.
Firstly, do I need to change just b (after “def propagate(w, b, X, Y)” , I set b=1.5) into matrix b (1 by 1)?
Secondly, In this error message,"operands could not be broadcast together with shapes (1,3) (1,4)
", what does (1,4) mean? I looked for each of elements of my code in which there are 1 by 4 matrix, but I didn’t find 1 by 4 matrix.

Please help me, best regards

Perhaps you are referencing global variables instead of the local parameter values.

Note that you have done several forms of “hard-coding” sizes by using [[b b b]], instead of just b and then you included np.ones((1,3)) in your cost code. It is always a mistake to assume that the dimensions are any fixed value, unless they specifically tell you to do that.

On the question about 1 x 4 matrices, notice that there are two separate test cases there: one you can see in the notebook (in which X is 2 x 3) and one that is imported from the file public_tests.py and that one has X with dimensions 3 x 4 and Y has dimension 1 x 4. So that’s where the 1 x 4 came from. Now the problem is that you’ve hard-coded the dimensions to be 1 x 3, which is exactly what that exception is complaining about.

1 Like

I understand and I could implement it without getting any complains , thank you so much Paulinpaloato!