No good solution for one_hot_matrix

If I reshape one_hot to (depth), the one_hot_matrix_test() is happy, but

new_y_test =

is not, producing a long stack of grief followed by 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], [].

If I reshape to (depth,1), now new_y_test = is happy but one_hot_matrix_test() is not, because it expects
tf.Tensor([0. 1. 0. 0.], shape=(4,), dtype=float32), (ie a one-dimensional vector vs. a single column matrix).

So I can either get 60% or 80% depending on which version I submit. Is the expected result of one_hot_matrix_test() just wrong?

Hi, @dredkey.

It looks like it was expecting the shape to be a vector (rank 1) but found a scalar (rank 0) instead. Did you specify it as shape=scalar? If you did, try shape=(scalar,) instead.

Good luck with the assignment :slight_smile:


Thanks, that appears to have done the trick for both tests (could have sworn I tried that earlier).

Not sure why just passing (depth) allowed ** one_hot_matrix_test()** to work.


Hi @nramon I have a question , why (scalar,) it gets like this?

Hi, @OkmiSantos.

Here’s the explanation :slight_smile: