Tensorflow_introduction one_hot_matrix_test Error


I have done the one_hot_matrix_test and got all tests passed and the right output. Then when I run the next cell for new_y_test and new_y_train I get an 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], .

Why do I get all tests passed but there is still an error?

I have the same problem.

I solved it. There was a problem with the shape in my one_hot_matrix function.
I hope you find it.

When I changed the shape to 6 instead of 4, It worked but the tests will not be accepted, can it be the tests are wrong?

You don’t have to put it literal, you have use the way to get the shape.
one_hot = tf.reshape(tf.one_hot(—, —, axis=0), (—,))
Here is a clue: depth – (int) Number of different classes that label can take


Ahhh I got it. Thank you!!

Thanks very helpful! I had the same problem. I had to watch the reshaping carefully.

Thanks, this helped a lot.
I implemented the same but as two lines but the grader didn’t accept it.
one_hot =tf.one_hot(-, -, axis=0)
It should be one line so the structure of the output is the same as requested.
Is this a bug from old version of TensorFlow or the way of implementation?

I would also add here that numpy reshape and tensorflow reshape have slightly different syntaxes at times. I run into a similar bug because of using old syntax.