General question on No. of layers in week2-A1

A short question about the iterations on the layers (Optimization Algorithms): Why in the provided code the iterations are until L+1? If the first layer is 1 and not 0, why we need an extra layer?
Thanks

It is because indexing in python is “0 based”. If I have an array with 4 elements, the first one is myArray[0] and the last one is myArray[3]. This same logic applies to loop indices as well. Try the following loops and watch what happens:

for ii in range(4):
    print(f"ii = {ii}")

for ii in range(1,5):
    print(f"ii = {ii}")

Take advantage of the interactive nature of an interpreted language like python. You don’t have to just wonder or hypothesize about what something does: you can try it and see. :nerd_face:

Note that you can insert a new cell in your notebook by clicking “Insert → Cell Below” to run an experiment like the above.