將 SparseTensor 的 ids 轉換為密集的布爾指標張量。
用法
tf.sparse.to_indicator(
sp_input, vocab_size, name=None
)參數
-
sp_input具有類型為int32或int64的values屬性的SparseTensor。 -
vocab_size一個標量 int64 張量(或 Python int),包含最後一個維度的新大小all(0 <= sp_input.values < vocab_size)。 -
name返回張量的名稱前綴(可選)
返回
- 一個密集的布爾指標張量,表示具有指定值的索引。
拋出
-
TypeError如果sp_input不是SparseTensor。
sp_input.indices 的最後一個維度被丟棄並替換為 sp_input 的值。如果 sp_input.dense_shape = [D0, D1, ..., Dn, K] ,則 output.shape = [D0, D1, ..., Dn, vocab_size] ,其中
output[d_0, d_1, ..., d_n, sp_input[d_0, d_1, ..., d_n, k]] = True
和 False 在 output 的其他地方。
例如,如果 sp_input.dense_shape = [2, 3, 4] 具有非空值:
[0, 0, 0]:0
[0, 1, 0]:10
[1, 0, 3]:103
[1, 1, 1]:150
[1, 1, 2]:149
[1, 1, 3]:150
[1, 2, 1]:121
和 vocab_size = 200 ,那麽輸出將是一個 [2, 3, 200] 密集布爾張量,除了位置之外的所有地方都是 False
(0, 0, 0), (0, 1, 10), (1, 0, 103), (1, 1, 149), (1, 1, 150),
(1, 2, 121).
請注意,輸入 SparseTensor 中允許重複。此操作可用於將 SparseTensor 轉換為密集格式,以便與需要密集張量的操作兼容。
輸入 SparseTensor 必須按行優先順序。
相關用法
- Python tf.sparse.to_dense用法及代碼示例
- Python tf.sparse.transpose用法及代碼示例
- Python tf.sparse.cross用法及代碼示例
- Python tf.sparse.mask用法及代碼示例
- Python tf.sparse.split用法及代碼示例
- Python tf.sparse.expand_dims用法及代碼示例
- Python tf.sparse.maximum用法及代碼示例
- Python tf.sparse.bincount用法及代碼示例
- Python tf.sparse.concat用法及代碼示例
- Python tf.sparse.reduce_sum用法及代碼示例
- Python tf.sparse.softmax用法及代碼示例
- Python tf.sparse.from_dense用法及代碼示例
- Python tf.sparse.retain用法及代碼示例
- Python tf.sparse.minimum用法及代碼示例
- Python tf.sparse.segment_sum用法及代碼示例
- Python tf.sparse.reduce_max用法及代碼示例
- Python tf.sparse.fill_empty_rows用法及代碼示例
- Python tf.sparse.slice用法及代碼示例
- Python tf.sparse.cross_hashed用法及代碼示例
- Python tf.sparse.reorder用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.sparse.to_indicator。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
