Tensorflow One Hot Encoder ?

  • 1 Answer(s)

    In Tensorflow, the tf.one_hot() is easy to use.

    Here, the depth=4 and indices=[0, 3]

    import tensorflow as tf
    res = tf.one_hot(indices=[0, 3], depth=4)
    with tf.Session() as sess:
        print sess.run(res)

    Note that when you provide index=-1 it will get all zeros in your one-hot vector

    Answered on December 15, 2018.
    Add Comment

  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.