Week 3 Programming Assignment error on model creation

All functions passed the tests, but when building the model I’m having this error and I don’t know how to fix it. Can you help me?

Capturar

Anytime you get a shape mismatch error, the first question is “ok, what shape is it?” Then the next question is “how did it get that way?” :nerd_face:

So put a print statement like this right before the assertion that is “throwing”:

print(f"A2.shape = {A2.shape}")

Then you have to track backwards to figure out why it came out to be the wrong shape. The other thing to realize here is that everyone’s notebooks are private, so we can’t just reach in and magically figure this out for you. The debugging work needs to be done by you. We can just give suggestions about how to approach the process.

I am sorry, I didn’t post my code. As seen in the trace, the error is happening in the function forward_propagation() and one of the parameters of this function is “parameters”, the output of the function initialize_parameters(). Here is my code for these functions:

initialize_parameters():
Capturar

forward_propagation():
Capturar

Both functions passed the tests.

Yes, those functions look correct. Now that we’ve confirmed that please edit your post to remove the source code. We’re not supposed to leave it hanging around for everyone to see.

Well, the point is that a perfectly correct subroutine can still throw errors if you pass it bogus parameter values, right? So the bug is almost certainly in your nn_model function. The most common sort of bug is referencing global variables instead of the parameters that are actually passed in or “hard-coding” certain assumptions about the dimensions or parameters like number of iterations. But with a shape mismatch, my guess that the problem is that you’re passing incorrect parameters to your initialize routine. Print the shapes you get back from initialize and see if they are what you’d expect.

Actually maybe that’s the first question: start by doing the “dimensional analysis”. What are the sizes of the various inputs? Based on that what should the shapes of A1 and A2 be? What actually are they?