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))
耐得住寂寞,才能登得顶
Gitee码云:https://gitee.com/lyc96/projects
原文地址:https://www.cnblogs.com/chenlove/p/13909840.html