tf.ragged.map_flat_values

View source on GitHub

Applies op to the values of one or more RaggedTensors.

tf.ragged.map_flat_values(
    op, *args, **kwargs
)

Replaces any RaggedTensor in args or kwargs with its flat_values tensor, and then calls op. Returns a RaggedTensor that is constructed from the input RaggedTensors' nested_row_splits and the value returned by the op.

If the input arguments contain multiple RaggedTensors, then they must have identical nested_row_splits.

Examples:

>>> rt = tf.ragged.constant([[1, 2, 3], [], [4, 5], [6]])
>>> map_flat_values(tf.ones_like, rt).to_list()
[[1, 1, 1], [], [1, 1], [1]]
>>> map_flat_values(tf.multiply, rt, rt).to_list()
[[1, 4, 9], [], [16, 25], [36]]
>>> map_flat_values(tf.add, rt, 5).to_list()
[[6, 7, 8], [], [9, 10], [11]]

Args:

Returns:

A RaggedTensor whose ragged_rank matches the ragged_rank of all input RaggedTensors.

Raises: