官方文档解释

one_hot(indices,#输入,这里是一维的depth,# one hot dimension.on_value=None,#output 默认1off_value=None,#output 默认0axis=None,dtype=None,name=None
)

例子:

indices = [0, 1, 2]  #输入数据(是个向量)需要编码的索引是[0,1,2]
depth = 3
tf.one_hot(indices, depth)  # output: [3 x 3]
# [[1., 0., 0.],
#  [0., 1., 0.],
#  [0., 0., 1.]]indices = [0, 2, -1, 1]  #输入数据(是个向量)的需要编码的索引是[0,2,-1,1]
depth = 3
tf.one_hot(indices, depth,on_value=5.0, off_value=0.0,axis=-1)  # output: [4 x 3]
# [[5.0, 0.0, 0.0],  # one_hot(0)  对位置0处的数据进行one_hot编码
#  [0.0, 0.0, 5.0],  # one_hot(2)  对位置2处的数据进行one_hot编码
#  [0.0, 0.0, 0.0],  # one_hot(-1) 对位置-1处的数据进行one_hot编码
#  [0.0, 5.0, 0.0]]  # one_hot(1)  对位置1处的数据进行one_hot编码indices = [[0, 2], [1, -1]]   #输入数据是个矩阵
depth = 3
tf.one_hot(indices, depth,on_value=1.0, off_value=0.0,axis=-1)  # output: [2 x 2 x 3]
# [[[1.0, 0.0, 0.0],   # one_hot(0)  对位置(0,0)处的数据进行one_hot编码
#   [0.0, 0.0, 1.0]],  # one_hot(2)  对位置(0,2)处的数据进行one_hot编码
#  [[0.0, 1.0, 0.0],   # one_hot(1)  对位置(1,1)处的数据进行one_hot编码
#   [0.0, 0.0, 0.0]]]  # one_hot(-1) 对位置(1,-1)处的数据进行one_hot编码

tf.one_hot()的用法相关推荐

  1. tf.one_hot函数用法

    具体用法如下: In [4]: y = tf.constant([1,2,3,0,2])In [5]: y = tf.one_hot(y,depth=4)In [7]: y Out[7]: <t ...

  2. Tensorflow中的tf.layers.batch_normalization()用法

    使用tf.layers.batch_normalization()需要三步: 在卷积层将激活函数设置为None. 使用batch_normalization. 使用激活函数激活. 需要特别注意的是:在 ...

  3. tf.nn.sampled_softmax_loss用法简单介绍

    tf.nn.sampled_softmax_loss用法简单介绍 在研究Skip-gram模型时遇到了采用方式的softmax,一时没有搞明白,下面做个小案例试一下. tf.nn.sampled_so ...

  4. tf.estimator的用法

    tf.estimator的用法 利用 tf.estimator 训练模型时需要写两个重要的函数,一个用于数据输入的函数(input_fn),另一个用于模型创建的函数(model_fn).下面逐一来说明 ...

  5. 值域范围 tf.clip_by_value的用法

    tf.clip_by_value的用法 tf.clip_by_value(A, min, max):输入一个张量A,把A中的每一个元素的值都压缩在min和max之间.小于min的让它等于min,大于m ...

  6. tf.one_hot

    tf.one_hot在看conditionGAN的时候注意到label的输入要把它转换成one-hot形式,再与噪声z进行tf.concat输入,之前看的时候忽略了,现在再看才算明白为什么. tf.o ...

  7. tf.one_hot()

    一.独热编码 独热编码(one-hot encoding),独热编码一般是在有监督学习中对数据集进行标注时候使用的,指的是在分类问题中,将存在数据类别的那一类用X表示,不存在的用Y表示,这里的X常常是 ...

  8. 【TensorFlow基础函数】tf.concat的用法

    tf.concat 的用法 TF官方的文档 tf.concat(values,axis,name='concat' ) 连接多个Tensor的操作 values 多个Tensor axis是哪个纬度 ...

  9. tf.matmul函数用法

    tf.matmul函数用法 函数:tf.matmul 表示:将矩阵 a 乘以矩阵 b,生成a * b matmul(a,b,transpose_a=False,transpose_b=False,ad ...

最新文章

  1. Java重写父类使用@Override时出现The method destroy() of type xxx must override a superclass method的问题解决...
  2. 脑机接口中的后门攻击
  3. JTA 深度历险 - 原理与实现---转
  4. 安装指定版本的minikube
  5. oracle edit历史,OGG-00952---oracle goldengate无法purge历史表和mark表处理一例
  6. 老话题:自己编写只截窗口客户区的截屏软件(VB2010)
  7. Java设计模式--代理模式与JDK动态代理,cglib动态代理
  8. 一步解决桌面文件需要管理员权限才能删除问题
  9. 创建一个分布式网络爬虫的故事
  10. ssh和telnet客户软件ZOC如何设置UTF-8
  11. 如何解决微服务的数据一致性分发问题?
  12. ubuntu18.04-ros-melodic-carlar安装教程详细指南
  13. 智慧工地车辆冲洗系统 工地渣土车未冲洗自动抓拍 yolo
  14. LeetCode575
  15. Arcgis中碎小斑块的处理
  16. 【每日一题】最大正方形面积——进阶,矩形面积
  17. JavaScript-ECMAScript编程
  18. 低版本物理机部署 高版本OVF 报“硬件系列vmx 12不受支持“解决办法
  19. 华为Taurus云原生数据库论文分析
  20. 联想开天s620z改win7和Linux,联想台式机预装win10改win7详细教程

热门文章

  1. (C#)Windows Shell 外壳编程系列总结
  2. 自动化测试环境搭建之RFS自动化测试框架全攻略
  3. Andriod studio 学习 之打包
  4. 麒麟信安系统chrome和360浏览器离线安装
  5. 软工实践 - 第八次作业
  6. 7000字和你聊聊如何设计一款高并发架构(建议收藏)
  7. 你又知不知道,日有所思,夜有所梦。
  8. 校招提前批之今日头条一面
  9. The server time zone value ‘й‘ is unrecognized or represents more than one time zone
  10. PowerDesigner创建概念模型转换为物理模型使表生成sql