#!/usr/bin/env python
# encoding: utf-8
'''
@author: lele Ye
@contact: 1750112338@qq.com
@software: pycharm 2018.2
@file: 02one_hot实验.py
@time: 2018/9/8 21:59
@desc:
'''
import tensorflow as tf
CLASS = 8
label = [x for x in range(8)]
labels = tf.convert_to_tensor(label)
one_hot_labels = tf.one_hot(indices=labels,depth=CLASS,on_value=1,off_value=0)
with tf.Session() as sess:
    sess.run(tf.global_variables_initializer())
    print("before one-hot:",sess.run(labels))
    print("after one-hot:\n", sess.run(one_hot_labels))

Logo

CSDN联合极客时间,共同打造面向开发者的精品内容学习社区,助力成长!

更多推荐