W4_A1_Ex-2_for loop to initialize parameters_getting key error for W2

I’m trying to implement the generalized for loop to initialize parameters. Sometimes depending on the range I am looping over (for l in range(1/2, L)) or the indices on my random code (layer_dims[l/l=1], layer_dims[l-1/l])), the test gives me an error for either W1 or W2.


I’m not sure what is wrong. Please help.

Hello @Nicklaus_Millican
Have you put your query under correct course and week? If you do so your query will get more visibility from mentors.

They gave you all the loop mechanics in the template code, right? All you have to do is fill in the actual calls to the appropriate random or zero init functions. They even gave you the LHS expressions for the two assignment statements in the comments.

If you modified the loop logic and want to get back to the original template code, there is a topic about that on the DLS FAQ Thread

BTW I used the little “edit pencil” on the title of your post to move it to the appropriate category.

Thank you, Paul.

Actually, I think I found a bug in the provided code. instead of starting each line as

parameters[‘W/b’ + str(L)] = …

I think it should be

parameters[‘W/b’ + str(l)] = …

Looking at it more closely, I think that the font used in the commented-out section is actually a lower-case l, but looks (due to the italics) an upper-case L.

Here’s what those comments look like as written:

        #(≈ 2 lines of code)
        # parameters['W' + str(l)] = ...
        # parameters['b' + str(l)] = ...
        # YOUR CODE STARTS HERE

Ok, yes, I see what you mean about how the “l” renders. But it’s actually worse here in Discourse than it is in the Jupyter notebook. I thought it looked pretty reasonable there. You might be able to mistake it for a “1” (the number one), but not a capital “L” :nerd_face:

But maybe we are all at the mercy of what browser we are using and what fonts we have loaded. So we have to fall back on conceptually understanding what is supposed to be happening …