將 op 應用於一個或多個 SparseTensor 的 .values 張量。
用法
tf.sparse.map_values(
op, *args, **kwargs
)參數
-
op應該應用於 SparseTensorvalues的操作。op通常是逐元素操作(例如math_ops.add),但可以使用任何保留形狀的操作。 -
*argsop的參數。 -
**kwargsop的關鍵字參數。
返回
-
SparseTensor,其indices和dense_shape與所有輸入SparseTensor的indices和dense_shape匹配。
拋出
-
ValueError如果 args 不包含SparseTensor,或者如果輸入SparseTensor的indices或dense_shape不相等。
將 args 或 kwargs 中的任何 SparseTensor 替換為其 values 張量(其中包含 SparseTensor 的非默認值),然後調用 op 。返回由輸入 SparseTensor s' indices , dense_shape 和 op 返回的值構成的 SparseTensor。
如果輸入參數包含多個 SparseTensor ,則它們必須具有相等的 indices 和密集形狀。
例子:
s = tf.sparse.from_dense([[1, 2, 0],
[0, 4, 0],
[1, 0, 0]])
tf.sparse.to_dense(tf.sparse.map_values(tf.ones_like, s)).numpy()
array([[1, 1, 0],
[0, 1, 0],
[1, 0, 0]], dtype=int32)
tf.sparse.to_dense(tf.sparse.map_values(tf.multiply, s, s)).numpy()
array([[ 1, 4, 0],
[ 0, 16, 0],
[ 1, 0, 0]], dtype=int32)
tf.sparse.to_dense(tf.sparse.map_values(tf.add, s, 5)).numpy()
array([[6, 7, 0],
[0, 9, 0],
[6, 0, 0]], dtype=int32)
注意:即使 tf.add(0, 5) != 0 ,隱式零也將保持不變。但是,如果稀疏張量包含任何顯式零,這些將受到映射的影響!
相關用法
- Python tf.sparse.mask用法及代碼示例
- Python tf.sparse.maximum用法及代碼示例
- Python tf.sparse.minimum用法及代碼示例
- Python tf.sparse.cross用法及代碼示例
- Python tf.sparse.split用法及代碼示例
- Python tf.sparse.to_dense用法及代碼示例
- Python tf.sparse.expand_dims用法及代碼示例
- Python tf.sparse.bincount用法及代碼示例
- Python tf.sparse.concat用法及代碼示例
- Python tf.sparse.transpose用法及代碼示例
- Python tf.sparse.reduce_sum用法及代碼示例
- Python tf.sparse.softmax用法及代碼示例
- Python tf.sparse.to_indicator用法及代碼示例
- Python tf.sparse.from_dense用法及代碼示例
- Python tf.sparse.retain用法及代碼示例
- 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用法及代碼示例
注:本文由純淨天空篩選整理自tensorflow.org大神的英文原創作品 tf.sparse.map_values。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
