Applies op to the .values tensor of one or more SparseTensors.
tf.sparse.map_values(op,*args,**kwargs)
Replaces any SparseTensor in args or kwargs with its values
tensor (which contains the non-default values for the SparseTensor),
and then calls op. Returns a SparseTensor that is constructed
from the input SparseTensors' indices, dense_shape, and the
value returned by the op.
If the input arguments contain multiple SparseTensors, then they must have
equal indices and dense shapes.
The operation that should be applied to the SparseTensor values. op
is typically an element-wise operation (such as math_ops.add), but any
operation that preserves the shape can be used.
*args
Arguments for op.
**kwargs
Keyword arguments for op.
Returns
A SparseTensor whose indices and dense_shape matches the indices
and dense_shape of all input SparseTensors.
Raises
ValueError
If args contains no SparseTensor, or if the indices
or dense_shapes of the input SparseTensors are not equal.
[null,null,["Last updated 2021-08-16 UTC."],[],[],null,["# tf.sparse.map_values\n\n\u003cbr /\u003e\n\n|-------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.6.0/tensorflow/python/ops/sparse_ops.py#L2865-L2929) |\n\nApplies `op` to the `.values` tensor of one or more `SparseTensor`s. \n\n tf.sparse.map_values(\n op, *args, **kwargs\n )\n\nReplaces any `SparseTensor` in `args` or `kwargs` with its `values`\ntensor (which contains the non-default values for the SparseTensor),\nand then calls `op`. Returns a `SparseTensor` that is constructed\nfrom the input `SparseTensor`s' `indices`, `dense_shape`, and the\nvalue returned by the `op`.\n\nIf the input arguments contain multiple `SparseTensor`s, then they must have\nequal `indices` and dense shapes.\n\n#### Examples:\n\n s = tf.sparse.from_dense([[1, 2, 0],\n [0, 4, 0],\n [1, 0, 0]])\n tf.sparse.to_dense(tf.sparse.map_values(tf.ones_like, s)).numpy()\n array([[1, 1, 0],\n [0, 1, 0],\n [1, 0, 0]], dtype=int32)\n\n tf.sparse.to_dense(tf.sparse.map_values(tf.multiply, s, s)).numpy()\n array([[ 1, 4, 0],\n [ 0, 16, 0],\n [ 1, 0, 0]], dtype=int32)\n\n tf.sparse.to_dense(tf.sparse.map_values(tf.add, s, 5)).numpy()\n array([[6, 7, 0],\n [0, 9, 0],\n [6, 0, 0]], dtype=int32)\n\n| **Note:** even though `tf.add(0, 5) != 0`, implicit zeros will remain unchanged. However, if the sparse tensor contains any explict zeros, these will be affected by the mapping!\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `op` | The operation that should be applied to the SparseTensor `values`. `op` is typically an element-wise operation (such as math_ops.add), but any operation that preserves the shape can be used. |\n| `*args` | Arguments for `op`. |\n| `**kwargs` | Keyword arguments for `op`. |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `SparseTensor` whose `indices` and `dense_shape` matches the `indices` and `dense_shape` of all input `SparseTensor`s. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Raises ------ ||\n|--------------|-----------------------------------------------------------------------------------------------------------------------|\n| `ValueError` | If args contains no `SparseTensor`, or if the `indices` or `dense_shape`s of the input `SparseTensor`s are not equal. |\n\n\u003cbr /\u003e"]]