重塑 SparseTensor 以在新的密集形狀中表示值。
用法
tf.sparse.reshape(
sp_input, shape, name=None
)參數
-
sp_input輸入SparseTensor。 -
shape一維(向量)int64Tensor指定表示的SparseTensor的新密集形狀。 -
name返回張量的名稱前綴(可選)
返回
-
SparseTensor具有相同的非空值,但具有由新密集形狀計算的索引。
拋出
-
TypeError如果sp_input不是SparseTensor。 -
ValueError如果參數shape請求的SparseTensor元素數量與sp_input不同。 -
ValueError如果shape具有多個推斷 (== -1) 維度。
此操作在表示的密集張量上具有與 reshape 相同的語義。 sp_input 中非空值的索引基於新的密集形狀重新計算,並返回包含新索引和新形狀的新 SparseTensor。 sp_input 中非空值的順序不變。
如果 shape 的一個分量是特殊值 -1,則計算該維度的大小,以便總密集大小保持不變。 shape 的最多一個分量可以是-1。 shape 隱含的密集元素的數量必須與最初由 sp_input 表示的密集元素的數量相同。
例如,如果 sp_input 具有形狀 [2, 3, 6] 和 indices /values :
[0, 0, 0]:a
[0, 0, 1]:b
[0, 1, 0]:c
[1, 0, 0]:d
[1, 2, 3]:e
和 shape 是 [9, -1] ,那麽輸出將是形狀為 [9, 4] 和 indices /values 的 SparseTensor :
[0, 0]:a
[0, 1]:b
[1, 2]:c
[4, 2]:d
[8, 1]:e
相關用法
- Python tf.sparse.reduce_sum用法及代碼示例
- Python tf.sparse.retain用法及代碼示例
- Python tf.sparse.reduce_max用法及代碼示例
- Python tf.sparse.reorder用法及代碼示例
- Python tf.sparse.cross用法及代碼示例
- Python tf.sparse.mask用法及代碼示例
- Python tf.sparse.split用法及代碼示例
- Python tf.sparse.to_dense用法及代碼示例
- Python tf.sparse.expand_dims用法及代碼示例
- Python tf.sparse.maximum用法及代碼示例
- Python tf.sparse.bincount用法及代碼示例
- Python tf.sparse.concat用法及代碼示例
- Python tf.sparse.transpose用法及代碼示例
- Python tf.sparse.softmax用法及代碼示例
- Python tf.sparse.to_indicator用法及代碼示例
- Python tf.sparse.from_dense用法及代碼示例
- Python tf.sparse.minimum用法及代碼示例
- Python tf.sparse.segment_sum用法及代碼示例
- Python tf.sparse.fill_empty_rows用法及代碼示例
- Python tf.sparse.slice用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.sparse.reshape。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
