tf.ragged.stack_dynamic_partitions
Stay organized with collections
Save and categorize content based on your preferences.
Stacks dynamic partitions of a Tensor or RaggedTensor.
tf.ragged.stack_dynamic_partitions(
data, partitions, num_partitions, name=None
)
Returns a RaggedTensor output
with num_partitions
rows, where the row
output[i]
is formed by stacking all slices data[j1...jN]
such that
partitions[j1...jN] = i
. Slices of data
are stacked in row-major
order.
If num_partitions
is an int
(not a Tensor
), then this is equivalent to
tf.ragged.stack(tf.dynamic_partition(data, partitions, num_partitions))
.
Example:
data = ['a', 'b', 'c', 'd', 'e']
partitions = [ 3, 0, 2, 2, 3]
num_partitions = 5
tf.ragged.stack_dynamic_partitions(data, partitions, num_partitions)
<tf.RaggedTensor [[b'b'], [], [b'c', b'd'], [b'a', b'e'], []]>
Args |
data
|
A Tensor or RaggedTensor containing the values to stack.
|
partitions
|
An int32 or int64 Tensor or RaggedTensor specifying the
partition that each slice of data should be added to. partitions.shape
must be a prefix of data.shape . Values must be greater than or equal to
zero, and less than num_partitions . partitions is not required to be
sorted.
|
num_partitions
|
An int32 or int64 scalar specifying the number of
partitions to output. This determines the number of rows in output .
|
name
|
A name prefix for the returned tensor (optional).
|
Returns |
A RaggedTensor containing the stacked partitions. The returned tensor
has the same dtype as data , and its shape is
[num_partitions, (D)] + data.shape[partitions.rank:] , where (D) is a
ragged dimension whose length is the number of data slices stacked for
each partition .
|
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 2023-03-17 UTC.
[null,null,["Last updated 2023-03-17 UTC."],[],[],null,["# tf.ragged.stack_dynamic_partitions\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.8.4/tensorflow/python/ops/ragged/ragged_array_ops.py#L569-L669) |\n\nStacks dynamic partitions of a Tensor or RaggedTensor.\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.stack_dynamic_partitions`](https://www.tensorflow.org/api_docs/python/tf/ragged/stack_dynamic_partitions)\n\n\u003cbr /\u003e\n\n tf.ragged.stack_dynamic_partitions(\n data, partitions, num_partitions, name=None\n )\n\nReturns a RaggedTensor `output` with `num_partitions` rows, where the row\n`output[i]` is formed by stacking all slices `data[j1...jN]` such that\n`partitions[j1...jN] = i`. Slices of `data` are stacked in row-major\norder.\n\nIf `num_partitions` is an `int` (not a `Tensor`), then this is equivalent to\n`tf.ragged.stack(tf.dynamic_partition(data, partitions, num_partitions))`.\n\n#### Example:\n\n data = ['a', 'b', 'c', 'd', 'e']\n partitions = [ 3, 0, 2, 2, 3]\n num_partitions = 5\n tf.ragged.stack_dynamic_partitions(data, partitions, num_partitions)\n \u003ctf.RaggedTensor [[b'b'], [], [b'c', b'd'], [b'a', b'e'], []]\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `data` | A `Tensor` or `RaggedTensor` containing the values to stack. |\n| `partitions` | An `int32` or `int64` `Tensor` or `RaggedTensor` specifying the partition that each slice of `data` should be added to. `partitions.shape` must be a prefix of `data.shape`. Values must be greater than or equal to zero, and less than `num_partitions`. `partitions` is not required to be sorted. |\n| `num_partitions` | An `int32` or `int64` scalar specifying the number of partitions to output. This determines the number of rows in `output`. |\n| `name` | A name prefix for the returned tensor (optional). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `RaggedTensor` containing the stacked partitions. The returned tensor has the same dtype as `data`, and its shape is `[num_partitions, (D)] + data.shape[partitions.rank:]`, where `(D)` is a ragged dimension whose length is the number of data slices stacked for each `partition`. ||\n\n\u003cbr /\u003e"]]