Course 1: W3 Exercise 8 (nn_model): A2 assertion Error

I am getting the AssertionError for Exersise 8: nn_model. There is a shape mismatch error for A2. I checked the forward_propogation function and printed all the shapes:

As much i am able to understand the shapes of these vectors should be:
Z1 (4,400) = W1 (4,2) * X (2,400) + b1 (4,1)

A1 (4,400)

Z2 (1,400) = W2 (1,4) * A1 (4,400) + b2 (1,1)

A2 (1,400)

Then only
A2.shape == (1, X.shape[1])

Hello @mohmmadakeeb,

Welcome to this community!

Your screenshots are showing lines that I can’t find in my most updated version of the lab, so it’s pretty difficult for me to make direct comparison with your results. However, one thing we can do here is that we can add those prints within the forward_propagation function like this:

Then, I ran through the notebook from the first cell down to the test cell directly below exercise 8 because sometimes the execution order matters, and I got:

I suggest you to do the same and compare your print results with mine. Your shape analysis is in the right direction and if we apply that to the case in my screenshot (which should also be the test case your code had failed), the shape of A2 should be (1, 4) because X.shape[1] is 4.

Cheers,
Raymond

2 Likes

Note that m = 400 for the real dataset we are using in this exercise, but the various “unit tests” for the individual functions use smaller test cases to make it easier to debug. You must write the code in a general way: be careful not to reference global variables when you implement forward_propagation and the other functions.