返回一个 one-hot 张量。
用法
tf.raw_ops.OneHot(
indices, depth, on_value, off_value, axis=-1, name=None
)参数
-
indices一个Tensor。必须是以下类型之一:uint8,int32,int64。 index 的张量。 -
depthTensor类型为int32。定义一个热维度的深度的标量。 -
on_value一个Tensor。一个标量,定义在indices[j] = i时填充输出的值。 -
off_value一个Tensor。必须与on_value具有相同的类型。一个标量,定义在indices[j] != i时填充输出的值。 -
axis可选的int。默认为-1。要填充的轴(默认值:-1,新的inner-most 轴)。 -
name操作的名称(可选)。
返回
-
一个
Tensor。具有与on_value相同的类型。
indices 中的索引表示的位置取值 on_value ,而所有其他位置取值 off_value 。
如果输入 indices 的等级为 N ,则输出的等级为 N+1 ,新轴在维度 axis 处创建(默认:新轴附加在末尾)。
如果 indices 是标量,则输出形状将是长度为 depth 的向量。
如果 indices 是长度为 features 的向量,则输出形状将为:
features x depth if axis == -1
depth x features if axis == 0
如果 indices 是形状为 [batch, features] 的矩阵(批次),则输出形状将为:
batch x features x depth if axis == -1
batch x depth x features if axis == 1
depth x batch x features if axis == 0
例子
假设
indices = [0, 2, -1, 1]
depth = 3
on_value = 5.0
off_value = 0.0
axis = -1
然后输出是 [4 x 3] :
output =
[5.0 0.0 0.0] // one_hot(0)
[0.0 0.0 5.0] // one_hot(2)
[0.0 0.0 0.0] // one_hot(-1)
[0.0 5.0 0.0] // one_hot(1)
假设
indices = [0, 2, -1, 1]
depth = 3
on_value = 0.0
off_value = 3.0
axis = 0
然后输出是 [3 x 4] :
output =
[0.0 3.0 3.0 3.0]
[3.0 3.0 3.0 0.0]
[3.0 3.0 3.0 3.0]
[3.0 0.0 3.0 3.0]
// ^ one_hot(0)
// ^ one_hot(2)
// ^ one_hot(-1)
// ^ one_hot(1)
假设
indices = [[0, 2], [1, -1]]
depth = 3
on_value = 1.0
off_value = 0.0
axis = -1
然后输出是 [2 x 2 x 3] :
output =
[
[1.0, 0.0, 0.0] // one_hot(0)
[0.0, 0.0, 1.0] // one_hot(2)
][
[0.0, 1.0, 0.0] // one_hot(1)
[0.0, 0.0, 0.0] // one_hot(-1)
]
相关用法
- Python tf.raw_ops.TPUReplicatedInput用法及代码示例
- Python tf.raw_ops.Bitcast用法及代码示例
- Python tf.raw_ops.SelfAdjointEigV2用法及代码示例
- Python tf.raw_ops.BatchMatMul用法及代码示例
- Python tf.raw_ops.ResourceScatterNdSub用法及代码示例
- Python tf.raw_ops.ReadVariableXlaSplitND用法及代码示例
- Python tf.raw_ops.GatherV2用法及代码示例
- Python tf.raw_ops.Expm1用法及代码示例
- Python tf.raw_ops.BitwiseAnd用法及代码示例
- Python tf.raw_ops.UniqueWithCounts用法及代码示例
- Python tf.raw_ops.DecodeGif用法及代码示例
- Python tf.raw_ops.Size用法及代码示例
- Python tf.raw_ops.ScatterUpdate用法及代码示例
- Python tf.raw_ops.ParallelConcat用法及代码示例
- Python tf.raw_ops.ScatterNdUpdate用法及代码示例
- Python tf.raw_ops.BatchToSpaceND用法及代码示例
- Python tf.raw_ops.TensorScatterMax用法及代码示例
- Python tf.raw_ops.DepthToSpace用法及代码示例
- Python tf.raw_ops.MutexLock用法及代码示例
- Python tf.raw_ops.QuantizeV2用法及代码示例
注:本文由纯净天空筛选整理自tensorflow.org大神的英文原创作品 tf.raw_ops.OneHot。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
