C1-W4-Deep Neural Network - Application - Too many values to unpack

Hi, I am trying to run the default code snippet of the course where it is like this:

parameters, costs = two_layer_model(train_x, train_y, layers_dims = (n_x, n_h, n_y), num_iterations = 2, print_cost=False)

print("Cost after first iteration: " + str(costs[0]))

two_layer_model_test(two_layer_model)

but I get the following error. Any thought?


I had to repeat the code snippet with this one but I can’t pass the assignment when I do.

parameters = two_layer_model(train_x, train_y, layers_dims = (n_x, n_h, n_y), num_iterations = 2500, print_cost=True)```

I refreshed the whole notebook and it worked.

The first error sounds like you must have modified the “return” statement of two_layer_model. That is part of the template given to you and there should be no need to modify it.

Note that using a single variable to hold the output of a function that returns multiple values has an effect in python that you might consider a surprise (not in a fun way): it creates a “tuple” containing all the output values. That’s why your added cell did not help. In other languages like MATLAB, using that syntax causes it to drop all the return values other than the first one, which is why I found that behavior surprising the first time I tripped over it in python. :nerd_face:

Getting a clean copy to see what the code originally looked like was the right idea!

1 Like