Course 2, Week 3, one_hot_matrix clarification

If I reshape the one_hot matrix to (depth, ), the tests pass. However, if I reshape the one_hot matrix to (depth, 1), the tests fail. Why is this? I thought we would need to use (depth, 1) to make sure we get a single-column matrix with rows = depth. Basically, I don’t understand why we need to use (depth, ).

8 Likes

Because

the shape of both y_pred and y_true are [batch_size, num_classes],

later on, when you need to calculate the cost using tf.keras.losses.CategoricalCrossentropy  |  TensorFlow v2.14.0

If you reshape to [depth, 1], the shape will be [batch_size, num_classes, 1] which throws an exception in the cost function.

However, you actually don’t need the reshape command here at all. I will report this upstream.

8 Likes

Sorry to ask, but, we should then, ignore this error?

I don’t remember if it gives you 100% pass when you submit with that error, if it does, then you can ignore it. If it doesn’t, change it, but remember that it’s not needed here.

1 Like

it seems that “[depth]” works for me, not “depth”, not “…, depth,1)”, not “…,(depth,1)”.

11 Likes