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 = y_test.map(one_hot_matrix)

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 = y_test.map(one_hot_matrix) 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:

4 Likes

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.

2 Likes

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

Hi, @OkmiSantos.

Here’s the explanation :slight_smile:

2 Likes