Course1 Week 4 assignment 2

Hello mentor!
When i run my code, i found this errors. I don’t know how to fix.
Please help me!
Best Regrades
Thank you

IndexError Traceback (most recent call last)
1 parameters, costs = two_layer_model(train_x, train_y, layers_dims = (n_x, n_h, n_y), num_iterations = 2, print_cost=False)
----> 3 print("Cost after first iteration: " + str(costs[0]))
5 two_layer_model_test(two_layer_model)

IndexError: list index out of range

Hi possga2000, welcome to the community and thanks for the question!

Index errors are one of the most common errors within the Python runtime environment, they happen when a value in the list does not exist. In this case, the error points to the costs list. So have a look at the costs list, and how you calculate the values of the costs list in your model, and see if you can figure out why the value does not exist. Good luck and let us know whether you can spot the error,

Best, Stephanus

I have the same error. Please helpppp

The variable costs is an empty list, have you modified the line with the print, mine looks different and I don’t think you were expected to complete that line (maybe I’m wrong I’m not sure if that part of the code was provided or you had to complete it).

In any case, the error is due to the fact that you’re trying to print costs[0] but at that point no cost has been added yet to the costs list.