tf.ragged.range
Stay organized with collections
Save and categorize content based on your preferences.
Returns a RaggedTensor
containing the specified sequences of numbers.
tf.ragged.range(
starts,
limits=None,
deltas=1,
dtype=None,
name=None,
row_splits_dtype=tf.dtypes.int64
)
Each row of the returned RaggedTensor
contains a single sequence:
ragged.range(starts, limits, deltas)[i] ==
tf.range(starts[i], limits[i], deltas[i])
If start[i] < limits[i] and deltas[i] > 0
, then output[i]
will be an
empty list. Similarly, if start[i] > limits[i] and deltas[i] < 0
, then
output[i]
will be an empty list. This behavior is consistent with the
Python range
function, but differs from the tf.range
op, which returns
an error for these cases.
Examples:
tf.ragged.range([3, 5, 2]).to_list()
[[0, 1, 2], [0, 1, 2, 3, 4], [0, 1]]
tf.ragged.range([0, 5, 8], [3, 3, 12]).to_list()
[[0, 1, 2], [], [8, 9, 10, 11]]
tf.ragged.range([0, 5, 8], [3, 3, 12], 2).to_list()
[[0, 2], [], [8, 10]]
The input tensors starts
, limits
, and deltas
may be scalars or vectors.
The vector inputs must all have the same size. Scalar inputs are broadcast
to match the size of the vector inputs.
Args |
starts
|
Vector or scalar Tensor . Specifies the first entry for each range
if limits is not None ; otherwise, specifies the range limits, and the
first entries default to 0 .
|
limits
|
Vector or scalar Tensor . Specifies the exclusive upper limits for
each range.
|
deltas
|
Vector or scalar Tensor . Specifies the increment for each range.
Defaults to 1 .
|
dtype
|
The type of the elements of the resulting tensor. If not specified,
then a value is chosen based on the other args.
|
name
|
A name for the operation.
|
row_splits_dtype
|
dtype for the returned RaggedTensor 's row_splits
tensor. One of tf.int32 or tf.int64 .
|
Returns |
A RaggedTensor of type dtype with ragged_rank=1 .
|
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-10-06 UTC.
[null,null,["Last updated 2023-10-06 UTC."],[],[],null,["# tf.ragged.range\n\n\u003cbr /\u003e\n\n|-----------------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.12.1/tensorflow/python/ops/ragged/ragged_math_ops.py#L43-L114) |\n\nReturns a `RaggedTensor` containing the specified sequences of numbers.\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.range`](https://www.tensorflow.org/api_docs/python/tf/ragged/range)\n\n\u003cbr /\u003e\n\n tf.ragged.range(\n starts,\n limits=None,\n deltas=1,\n dtype=None,\n name=None,\n row_splits_dtype=../../tf/dtypes#int64\n )\n\nEach row of the returned `RaggedTensor` contains a single sequence: \n\n ragged.range(starts, limits, deltas)[i] ==\n tf.range(starts[i], limits[i], deltas[i])\n\nIf `start[i] \u003c limits[i] and deltas[i] \u003e 0`, then `output[i]` will be an\nempty list. Similarly, if `start[i] \u003e limits[i] and deltas[i] \u003c 0`, then\n`output[i]` will be an empty list. This behavior is consistent with the\nPython `range` function, but differs from the [`tf.range`](../../tf/range) op, which returns\nan error for these cases.\n\n#### Examples:\n\n tf.ragged.range([3, 5, 2]).to_list()\n [[0, 1, 2], [0, 1, 2, 3, 4], [0, 1]]\n tf.ragged.range([0, 5, 8], [3, 3, 12]).to_list()\n [[0, 1, 2], [], [8, 9, 10, 11]]\n tf.ragged.range([0, 5, 8], [3, 3, 12], 2).to_list()\n [[0, 2], [], [8, 10]]\n\nThe input tensors `starts`, `limits`, and `deltas` may be scalars or vectors.\nThe vector inputs must all have the same size. Scalar inputs are broadcast\nto match the size of the vector inputs.\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `starts` | Vector or scalar `Tensor`. Specifies the first entry for each range if `limits` is not `None`; otherwise, specifies the range limits, and the first entries default to `0`. |\n| `limits` | Vector or scalar `Tensor`. Specifies the exclusive upper limits for each range. |\n| `deltas` | Vector or scalar `Tensor`. Specifies the increment for each range. Defaults to `1`. |\n| `dtype` | The type of the elements of the resulting tensor. If not specified, then a value is chosen based on the other args. |\n| `name` | A name for the operation. |\n| `row_splits_dtype` | `dtype` for the returned `RaggedTensor`'s `row_splits` tensor. One of [`tf.int32`](../../tf#int32) or [`tf.int64`](../../tf#int64). |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| A `RaggedTensor` of type `dtype` with `ragged_rank=1`. ||\n\n\u003cbr /\u003e"]]