Tensorflow 的tf.one_hot()功能:dense to one hot

本篇博客详细介绍了Tensorflow中的tf.one_hot()函数,用于将稠密编码的数据转换为独热编码。文章涵盖了函数的参数设置,包括indices、depth、on_value、off_value、axis和dtype,并强调了数据类型匹配的重要性。通过该函数,可以在指定轴上创建一个独热维度的张量,这对于分类问题尤其有用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import tensorflow as tf
indices = [[3], [5], [0], [7]]
indices = tf.concat(0, indices)
indices = tf.reshape(indice, (4, 1))
a = tf.one_hot(indices, depth=10, on_value=None, off_value=None, axis=None, dtype=None, name=None)
print ("a is : ")
print a
b = tf.reshape(a, (4, 10))
print ("a is : ")
print b

'''
a is : 
Tensor("one_hot:0", shape=(4, 1, 10), dtype=float32)
a is : 
Tensor("Reshape_1:0", shape=(4, 10), dtype=float32)
'''
Args:
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值