tf.ragged.map_flat_values
Stay organized with collections
Save and categorize content based on your preferences.
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 RaggedTensor
s' nested_row_splits
and the value returned by
the op
.
If the input arguments contain multiple RaggedTensor
s, 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 |
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.
|
*args
|
Arguments for op .
|
**kwargs
|
Keyword arguments for op .
|
Returns |
A RaggedTensor whose ragged_rank matches the ragged_rank of all
input RaggedTensor s.
|
Raises |
ValueError
|
If args contains no RaggedTensors , or if the nested_splits
of the input RaggedTensor s are not identical.
|
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2021-02-18 UTC.
[null,null,["Last updated 2021-02-18 UTC."],[],[],null,["# tf.ragged.map_flat_values\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------|\n| [TensorFlow 1 version](/versions/r1.15/api_docs/python/tf/ragged/map_flat_values) | [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.4.0/tensorflow/python/ops/ragged/ragged_functional_ops.py#L32-L116) |\n\nApplies `op` to the 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\nReplaces any `RaggedTensor` in `args` or `kwargs` with its `flat_values`\ntensor, and then calls `op`. Returns a `RaggedTensor` that is constructed\nfrom the input `RaggedTensor`s' `nested_row_splits` and the value returned by\nthe `op`.\n\nIf the input arguments contain multiple `RaggedTensor`s, then they must have\nidentical `nested_row_splits`.\n\n#### Examples:\n\n rt = tf.ragged.constant([[1, 2, 3], [], [4, 5], [6]])\n map_flat_values(tf.ones_like, rt).to_list()\n [[1, 1, 1], [], [1, 1], [1]]\n map_flat_values(tf.multiply, rt, rt).to_list()\n [[1, 4, 9], [], [16, 25], [36]]\n map_flat_values(tf.add, rt, 5).to_list()\n [[6, 7, 8], [], [9, 10], [11]]\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"]]