Week 4: indexing into parameters in L_model_forward()

In the first week 4 coding assignment, after opening the test function and my function and comparing my caches to the predicted caches, I determined that the for loop I used delivers the correct results, but the AL layer is incorrect. To create this layer, I have to use the same function as in the for loop, but with different arguments:

AL,cache=linear_activation_forward(A_prev,parameters[‘W’+str(/index)], parameters[‘b’+str(/index)], “sigmoid”)

I am struggling to figure out what the value of /index should be. I tried using, l, L, l+1, L+1, all of which returned the incorrect result. Can someone offer some guidance?


You can debug this by printing the various values of l (lowercase ell) in the loop and then see what you need when you fall out of the loop and handle the output layer. Print the value of L as well.

Also note that there’s more to be careful about here than just the layer number to use to look up W and b: also make sure you have the correct A value as input. it should be the A that was output by the last hidden layer.

1 Like