tensorflow打印输出张量以及tf.one_hot()函数简介

import tensorflow as tf  
      
classes = 3
labels = tf.constant([0,1,2]) # 输入的元素值最小为0,最大为2
output = tf.one_hot(labels,classes)

sess = tf.Session()
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    output = sess.run(output)
    print("output of one-hot is : ",output)

# ('output of one-hot is : ', array([[ 1.,  0.,  0.],
#       [ 0.,  1.,  0.],
#       [ 0.,  0.,  1.]], dtype=float32))

 

posted @ 2020-11-01 16:00  Python研究者  阅读(290)  评论(0编辑  收藏  举报