Week 4 assignment deep neural network application

That error means that the costs array returned by your two_layer_model function must be an empty list. So how could that happen? With 2 iterations, you should have returned one cost value for iteration 0, right?

Are you sure you didn’t copy over the template code from the previous version of the course? Here’s what the template code should look like for the last section of the two_layer_model function:

        # Print the cost every 100 training example
        if print_cost and i % 100 == 0 or i == num_iterations - 1:
            print("Cost after iteration {}: {}".format(i, np.squeeze(cost)))
        if i % 100 == 0 or i == num_iterations:
            costs.append(cost)

    return parameters, costs

In the old version of the notebook from the previous course, the costs are not added to the array if print_cost is False, as it is in the test case in question here. You can’t just copy over everything from the previous course without looking. It gets you in trouble in some ways, e.g. this example.

1 Like