# Cannot compute Cost due to Error course 2 week 3

I’m unable to complete the assignment because of a failure in the provided code.
Exercise 3 - one_hot_matrix passes all tests but an error occurs:
`"NameError: name 'new_y_test' is not defined"`

This causes a failure later when computing the cost function.
Any ideas?

Thank you!

EDIT:
I have closed down my browser, reopend the lab, and rerun all sections. I still get this error.

Where is new_y_test defined? Did the cell throw an error? Run it again. Then add a cell right after that to print the value or the shape or anything to reference that variable. What happens?

Looking at the code, this probably means there is a bug in your one_hot_matrix routine. E.g. you hardcoded the dimension value or the like.

I’ll continue troubleshooting … but new_y_test is defined here:

`new_y_test = y_test.map(one_hot_matrix)`

in a code-block after the testing code-block.
my Cost function does pass testing.

my one_hot line is defined as:

`one_hot = tf.reshape(tf.one_hot(label, depth, axis=0), (depth)) `

Try using (depth,) as the shape on the “reshape”. The point is it needs to be a 1D tensor, not a 0D tensor.

3 Likes

isn’t that what I have already?

No, that’s the point: (depth,) is not the same thing as (depth). Try it and see.

When you do it your way, you pass the unit test for one_hot_matrix, but the cell that creates new_y_test throws the following error:

` ValueError: Shape must be rank 1 but is rank 0 for '{{node Reshape}} = Reshape[T=DT_FLOAT, Tshape=DT_INT32](one_hot, Reshape/shape)' with input shapes: [6], [].`

That is why new_y_test is not defined: the cell that creates it threw an error. Did you not see that when you looked before?

1 Like

Mind you, I think you can legitimately claim that the unit test for one_hot_matrix is broken if it passes incorrect code. I’ll take a look at why that happens and file a bug if I can see how to fix it.

OH! You have a comma in there!
I see what you mean now.
That does work. Thank you.

And yes … I did realize that that’s why that variable wasn’t being instantiated …