Replaces any RaggedTensor in args or kwargs with its flat_values
tensor (which collapses all ragged dimensions), 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.
This operation is generally used to apply elementwise operations to each value
in a RaggedTensor.
The operation that should be applied to the RaggedTensor flat_values.
op is typically an element-wise operation (such as math_ops.add), but
any operation that preserves the size of the outermost dimension can be
used. I.e., shape[0] of the value returned by op must match
shape[0] of the RaggedTensors' flat_values tensors.
*args
Arguments for op.
**kwargs
Keyword arguments for op.
Returns
A RaggedTensor whose ragged_rank matches the ragged_rank of all
input RaggedTensors.
Raises
ValueError
If args contains no RaggedTensors, or if the nested_splits
of the input RaggedTensors are not identical.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-04-26 UTC."],[],[],null,["# tf.ragged.map_flat_values\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/ragged/ragged_functional_ops.py#L25-L136) |\n\nApplies `op` to the `flat_values` of one or more RaggedTensors.\n\n#### View aliases\n\n\n**Compat aliases for migration**\n\nSee\n[Migration guide](https://www.tensorflow.org/guide/migrate) for\nmore details.\n\n[`tf.compat.v1.ragged.map_flat_values`](https://www.tensorflow.org/api_docs/python/tf/ragged/map_flat_values)\n\n\u003cbr /\u003e\n\n tf.ragged.map_flat_values(\n op, *args, **kwargs\n )\n\n### Used in the notebooks\n\n| Used in the guide |\n|--------------------------------------------------------------------|\n| - [Ragged tensors](https://www.tensorflow.org/guide/ragged_tensor) |\n\nReplaces any `RaggedTensor` in `args` or `kwargs` with its `flat_values`\ntensor (which collapses all ragged dimensions), and then calls `op`. Returns\na `RaggedTensor` that is constructed from the input `RaggedTensor`s'\n`nested_row_splits` and the value returned by the `op`.\n\nIf the input arguments contain multiple `RaggedTensor`s, then they must have\nidentical `nested_row_splits`.\n\nThis operation is generally used to apply elementwise operations to each value\nin a `RaggedTensor`.\n| **Warning:** [`tf.ragged.map_flat_values`](../../tf/ragged/map_flat_values) does *not* apply `op` to each row of a ragged tensor. This difference is important for non-elementwise operations, such as [`tf.reduce_sum`](../../tf/math/reduce_sum). If you wish to apply a non-elementwise operation to each row of a ragged tensor, use [`tf.map_fn`](../../tf/map_fn) instead. (You may need to specify an `output_signature` when using [`tf.map_fn`](../../tf/map_fn) with ragged tensors.)\n\n#### Examples:\n\n rt = tf.ragged.constant([[1, 2, 3], [], [4, 5], [6]])\n tf.ragged.map_flat_values(tf.ones_like, rt)\n \u003ctf.RaggedTensor [[1, 1, 1], [], [1, 1], [1]]\u003e\n tf.ragged.map_flat_values(tf.multiply, rt, rt)\n \u003ctf.RaggedTensor [[1, 4, 9], [], [16, 25], [36]]\u003e\n tf.ragged.map_flat_values(tf.add, rt, 5)\n \u003ctf.RaggedTensor [[6, 7, 8], [], [9, 10], [11]]\u003e\n\nExample with a non-elementwise operation (note that `map_flat_values` and\n`map_fn` return different results): \n\n rt = tf.ragged.constant([[1.0, 3.0], [], [3.0, 6.0, 3.0]])\n def normalized(x):\n return x / tf.reduce_sum(x)\n tf.ragged.map_flat_values(normalized, rt)\n \u003ctf.RaggedTensor [[0.0625, 0.1875], [], [0.1875, 0.375, 0.1875]]\u003e\n tf.map_fn(normalized, rt)\n \u003ctf.RaggedTensor [[0.25, 0.75], [], [0.25, 0.5, 0.25]]\u003e\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 RaggedTensor `flat_values`. `op` is typically an element-wise operation (such as math_ops.add), but any operation that preserves the size of the outermost dimension can be used. I.e., `shape[0]` of the value returned by `op` must match `shape[0]` of the `RaggedTensor`s' `flat_values` tensors. |\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 `RaggedTensor` whose `ragged_rank` matches the `ragged_rank` of all input `RaggedTensor`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 `RaggedTensors`, or if the `nested_splits` of the input `RaggedTensor`s are not identical. |\n\n\u003cbr /\u003e"]]