Assignment problem


unable to solve week 4 assignment please help anyone have not able to solve for 7 days

Hi Sudipta,
Could you please paste which problem is not passing. We could take one problem at a time.
Also, there is a way by which you can share the link to your notebook. Please go to the help section on the right of the notebook.

Hi, @Sudipta_Mukherjee1. I have edited your message so that you .png is visible (a closing parenthesis on the source file was missing). But, it is only a partial view of the traceback. As @vsnupoudel points out, it would be useful to see the entire traceback. Thanks!

Hi Sudipta,
IndexError has to do mostly with Python lists ( or arrays). Python indexing in lists starts from 0. If you came from R, this might be confusing.
Please check the article below, or similar articles for details:

  • Also, there is a way to copy paste entire traceback (error log) between two such quotations " ``` your entire error log ```` "

This is the third thread that you have posted about this same problem. I gave you suggestions on the other threads about how to investigate this. The problem is that your costs value that you return from two_layer_model is a python list (which is correct), but it has 0 entries (which is incorrect). So now the question is how could that happen? Look at the logic that updates the costs array. Why is it not getting executed?

I had a private conversation with Sudipta. It turns out that the problem is they are using an old version of the template code for two_layer_model which only appends to the costs list when print_cost is True, but in the new version of the notebook that flag is passed as False on this test case and the template logic has been changed to this:


        # Print the cost every 100 iterations
        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

So you can see that the “append” happens even if print_cost = False. (Note that this is part of the given template code that is provided by the notebook, so it’s ok to share it.)

Note that this change to the notebooks was made over a year ago in early April 2021. If you have a saved notebook from before the upgrade to the courses, you can’t just blindly copy the code to the new version of the course. You have to compare carefully to notice this type of changes, which are pretty widespread in the new versions. Also note that if you copy a solution from someone else that is a) against the rules and b) can expose you to this sort of problem. So it’s not a good idea just in general, since you can’t tell how old the notebook you are borrowing is. :nerd_face: