返回一個 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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
