tf.sparse.map_values

Applies op to the .values tensor of one or more SparseTensors.

Used in the notebooks

Used in the guide

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.

Examples:

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],