标签:03 26 函数 service cc hot tf tensorflow
import numpy as np
import tensorflow as tf
indices = [0, 1, 1] # rank=1
depth = 8
a = tf.one_hot(indices, depth) # rank=2,输出为[3,3]
indices=[0,2,-2,1] #rank=1
depth=7
b=tf.one_hot(indices,depth,on_value=5.0,off_value=1.0,axis=-1)
print(a)
print(b)
结果:
tf.Tensor(
[[1. 0. 0. 0. 0. 0. 0. 0.]
[0. 1. 0. 0. 0. 0. 0. 0.]
[0. 1. 0. 0. 0. 0. 0. 0.]], shape=(3, 8), dtype=float32)
tf.Tensor(
[[5. 1. 1. 1. 1. 1. 1.]
[1. 1. 5. 1. 1. 1. 1.]
[1. 1. 1. 1. 1. 1. 1.]
[1. 5. 1. 1. 1. 1. 1.]], shape=(4, 7), dtype=float32)
2022-01-26 23:03:21.608213: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x2181e053ce0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2022-01-26 23:03:21.608562: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version
2022-01-26 23:03:21.608979: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2022-01-26 23:03:21.609264: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]
Process finished with exit code 0
one_hot(a,b)中,b代表向量的长度
a为列表,代表每个行向量中主元素(on_value)的值为1(若设定,则为设定值),其余元素(off_value)的值为0(若设定,则为设定值)。
标签:03,26,函数,service,cc,hot,tf,tensorflow 来源: https://blog.csdn.net/weixin_45365242/article/details/122710354
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。