import tensorflow as tf
indices = [[3], [5], [0], [7]]
indices = tf.concat(0, indices)
indices = tf.reshape(indice, (4, 1))
a = tf.one_hot(indices, depth=10, on_value=None, off_value=None, axis=None, dtype=None, name=None)
print ("a is : ")
print a
b = tf.reshape(a, (4, 10))
print ("a is : ")
print b
'''
a is :
Tensor("one_hot:0", shape=(4, 1, 10), dtype=float32)
a is :
Tensor("Reshape_1:0", shape=(4, 10), dtype=float32)
'''
Args:
indices: A Tensor of
indices.
depth: A scalar
defining the depth of the one hot dimension.
on_value: A scalar
defining the value to fill in output when indices[j] = i. (default: 1)
off_value: A scalar
defining the value to fill in output when indices[j] != i. (default: 0)
axis: The axis
to fill (default: -1, a new inner-most axis).
dtype: The data
type of the output tensor.
Returns:
output: The one-hot
tensor.
Raises:
TypeError: If dtype
of either on_value or off_value don't
match dtype
TypeError: If dtype
of on_value and off_value don't
match one another