C1 W4 part2 EX5

Hi, I’m new on python. I just encountered this error and I can’t figure out what I’m mistaking…pls if you can help me…


![error2|690x398](image removed by moderator as it contained grade cell codes, posting on public post is against community guidelines)

str(1) is incorrect in linear_activation_forward in line 29

Thanks, but If I remove it, it says " KeyError: ‘W’ "
Also, I’m sorry for having published code.

You are using str(one). Remember to use the layer index.

Hi @Spacedhictory ,

The variable ‘parameters’ is a python dictionary, which is a data type for storing a collection of key: value pairs. When constructing the ‘key’ for the weights of a particular layer:
parameters[‘W’+str(l)] - here, l is the lower case of L, not the numeric value of 1, as l is an index used in the for loop.

2 Likes

Many thanks @Kic , I understand. But now the code is giving another error " AssertionError: Not all tests were passed for L_model_forward. Check your equations and avoid using global variables inside the function. " as AL.shape is (3,4) instead of (1,4). Where have I to look now? Which type of error is this? I just correct as you told me.
This is driving me crazy…

with only 1 test passed and 2 failed

The best way to debug that type of problem is to start with the “dimensional analysis” on that test case, so that you know what should be happening. Here’s a thread which walks you through that.

Thank you a lot.

@Spacedhictory also, personally (having seen many of these now myself), it helps to ‘walk back’ up the error thread.

I mean here, at least at a quick glance, perhaps the source of your error is suggested in the last output-- But in other cases, where a lot of other libraries/tests are being loaded, your error is more likely to be at the top of the list (it kind of just ‘percolates down’).

So start at the end and work your way back up.