C1_W2_A2: Logistic Regression with a Neural Network mindset

Hello, I’ve been having some problems completing the graded programming assignment and would appreciate some help.
First of all, I had been getting this error for Exercise 5: Propagate:

The only way I was able to get rid of it was to transpose the elements np.log(A) and np.log(1-A). Though it was weird to deviate from the proposed formulas, it worked, the tests were passed, and I moved on. The thing is I still don’t quite understand why I had to deviate from the formulas so I would appreciate some explanation regarding that.
Second of all, I am unable to complete Exercise 8: Model due to the following error:

Though I think I understand what the problem is, I have no idea how to solve it. Would appreciate some guidance with that as well.

You should know by know that in vectorised form the linear regression equation becomes:

Y =theta.T×X + b (these are all vectors) the formulas might have ommited this because its understandable by know.

In any case you make sure that to multiply 2 matrices you need to align their sizes such as if A is m×n than B is n×any, and I think your second issue has still to do with this. Check this particularly for the sigmoid calculation.


You’re right, thank you. I was giving the wrong dimension of X_train to initialize_with_zeros, and as a result w.T and X were not aligned for sigmoid calculations. However, now that I’ve changed that I’m getting the following error, which origins I have literally no idea about:

The error tells you that the expected variable should be a numpy array whilst it is a tuple. A python course would be good for you, and there are plenty online.


You have to call predict function to calculate Y_prediction_train and Y_prediction_test.

1 Like

Thank you! I missed it for one of them for some reason