将 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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
