It looks like the type of the costs value returned by your two_layer_model is incorrect. It must be a 0 dimensional array, but it should be a python list, right? They gave you the code to manage the costs array as part of the template, so there should have been no need to change it. If you want to get a fresh copy of the notebook to see what it originally looked like, there is a topic about that on the FAQ Thread.
You can’t modify the test cell, but I did “Insert → Cell Below” and added this code after the test cell:
print(f"type(costs) = {type(costs)}")
type(costs) = <class 'list'>
What do you see if you try that?
yes its show type(costs) = <class ‘list’>
but sir i dont get it if we cant edit this cell how can we make that code run
The point is that if the test fails, that is not a problem with the test, right? It’s a problem with your code. We just haven’t figured out what the problem is yet. So we need to think harder. If you believe you have proved that costs really is a list, then it must be an empty list or something else is wrong with it. So after you print the type, add another print statement to show the length:
print(f"len(costs) = {len(costs)}")
Here’s what I get from that:
len(costs) = 1
What do you see? If it’s 0, then the next question is, how did that happen?
Update: I tried adding a bug to produce a 0 length costs array and I get a different error than the one you show:
skip the append
Cost after iteration 1: 0.6926114346158595
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-15-f9ec5304d38d> in <module>
1 parameters, costs = two_layer_model(train_x, train_y, layers_dims = (n_x, n_h, n_y), num_iterations = 2, print_cost=False)
2
----> 3 print("Cost after first iteration: " + str(costs[0]))
4
5 two_layer_model_test(two_layer_model)
IndexError: list index out of range
So you must be doing something different. Now I’m really curious what the mistake is!