Exercise 4 seems not to run after I passed Exercise 3

When creating a post, please add:

  • Week # must be added in the tags option of the post.
  • Link to the classroom item you are referring to:
  • Description (include relevant info but please do not post solution code or your entire notebook)

Hello, In the course deep learning specialization, month 2 week 3, I have following problem:

I passed the exercise 1, 2 and 3.

After exercise 3, after getting the message “All test passed” I get error messages between exercise 3 and 4.

The program seems not to run through exercise 4. I don’t get a failure message and I can not even execute a print statement, which usually works.


Can anyone tell me, why it does not runt through, (even with an error message if my code is wrong)?

Thank you.

1 Like

You don’t show us enough of the exception trace to find the line of code that is actually “throwing”, but the error message is pretty clear. It looks like your one hot function is not getting called correctly.

Actually I’ve got a theory: I’ll bet you changed the definition of the one_hot_matrix function. Here’s what it looks like as it was given to you:

def one_hot_matrix(label, C=6):

I’ll bet you changed it to be this:

def one_hot_matrix(label, C):

It is generally a mistake to change code outside of the “YOUR CODE HERE” segments. It’s not illegal and the grader doesn’t actually look at your code (it only calls your functions), but when you change other code that you don’t need to change, you need to be very clear that you understand what you are doing.

Notice the difference between the two definitions: in the original one C is an optional (“keyword”) parameter with a default value of 6. That is required, because the code calls it using the TF “map()” function which only passes one argument. You could argue that what they did there was a bit awkward and I wouldn’t disagree with you. But it is what it is …

1 Like

In fact I might have done it, but not intentionally since this is not the area I should put code in. I am surprised I am even able to do it. It must have happened while I was not on my laptop or doing something different.
But changing it to C=6 worked.

Thank you.

1 Like