tf.range
Stay organized with collections
Save and categorize content based on your preferences.
Creates a sequence of numbers.
tf.range(limit, delta=1, dtype=None, name='range')
tf.range(start, limit, delta=1, dtype=None, name='range')
Used in the notebooks
Used in the guide |
Used in the tutorials |
|
|
Creates a sequence of numbers that begins at start
and extends by
increments of delta
up to but not including limit
.
The dtype of the resulting tensor is inferred from the inputs unless
it is provided explicitly.
Like the Python builtin range
, start
defaults to 0, so that
range(n) = range(0, n)
.
For example:
start = 3
limit = 18
delta = 3
tf.range(start, limit, delta)
<tf.Tensor: shape=(5,), dtype=int32,
numpy=array([ 3, 6, 9, 12, 15], dtype=int32)>
start = 3
limit = 1
delta = -0.5
tf.range(start, limit, delta)
<tf.Tensor: shape=(4,), dtype=float32,
numpy=array([3. , 2.5, 2. , 1.5], dtype=float32)>
limit = 5
tf.range(limit)
<tf.Tensor: shape=(5,), dtype=int32,
numpy=array([0, 1, 2, 3, 4], dtype=int32)>
Args |
start
|
A 0-D Tensor (scalar). Acts as first entry in the range if limit
is not None; otherwise, acts as range limit and first entry defaults to 0.
|
limit
|
A 0-D Tensor (scalar). Upper limit of sequence, exclusive. If None,
defaults to the value of start while the first entry of the range
defaults to 0.
|
delta
|
A 0-D Tensor (scalar). Number that increments start . Defaults to
1.
|
dtype
|
The type of the elements of the resulting tensor.
|
name
|
A name for the operation. Defaults to "range".
|
Returns |
An 1-D Tensor of type dtype .
|
Equivalent to np.arange
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 2024-04-26 UTC.
[[["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.range\n\n\u003cbr /\u003e\n\n|------------------------------------------------------------------------------------------------------------------------------|\n| [View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.16.1/tensorflow/python/ops/math_ops.py#L1940-L2021) |\n\nCreates a sequence 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.range`](https://www.tensorflow.org/api_docs/python/tf/range)\n\n\u003cbr /\u003e\n\n tf.range(limit, delta=1, dtype=None, name='range')\n tf.range(start, limit, delta=1, dtype=None, name='range')\n\n### Used in the notebooks\n\n| Used in the guide | Used in the tutorials |\n|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| - [DTensor concepts](https://www.tensorflow.org/guide/dtensor_overview) - [Better performance with tf.function](https://www.tensorflow.org/guide/function) - [Training checkpoints](https://www.tensorflow.org/guide/checkpoint) - [Estimators](https://www.tensorflow.org/guide/estimator) - [Optimizers with Core APIs](https://www.tensorflow.org/guide/core/optimizers_core) | - [Integrated gradients](https://www.tensorflow.org/tutorials/interpretability/integrated_gradients) - [DeepDream](https://www.tensorflow.org/tutorials/generative/deepdream) - [Save and load a model using a distribution strategy](https://www.tensorflow.org/tutorials/distribute/save_and_load) - [Playing CartPole with the Actor-Critic method](https://www.tensorflow.org/tutorials/reinforcement_learning/actor_critic) - [Distributed Input](https://www.tensorflow.org/tutorials/distribute/input) |\n\nCreates a sequence of numbers that begins at `start` and extends by\nincrements of `delta` up to but not including `limit`.\n\nThe dtype of the resulting tensor is inferred from the inputs unless\nit is provided explicitly.\n\nLike the Python builtin `range`, `start` defaults to 0, so that\n`range(n) = range(0, n)`.\n\n#### For example:\n\n start = 3\n limit = 18\n delta = 3\n tf.range(start, limit, delta)\n \u003ctf.Tensor: shape=(5,), dtype=int32,\n numpy=array([ 3, 6, 9, 12, 15], dtype=int32)\u003e\n\n start = 3\n limit = 1\n delta = -0.5\n tf.range(start, limit, delta)\n \u003ctf.Tensor: shape=(4,), dtype=float32,\n numpy=array([3. , 2.5, 2. , 1.5], dtype=float32)\u003e\n\n limit = 5\n tf.range(limit)\n \u003ctf.Tensor: shape=(5,), dtype=int32,\n numpy=array([0, 1, 2, 3, 4], dtype=int32)\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Args ---- ||\n|---------|----------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `start` | A 0-D `Tensor` (scalar). Acts as first entry in the range if `limit` is not None; otherwise, acts as range limit and first entry defaults to 0. |\n| `limit` | A 0-D `Tensor` (scalar). Upper limit of sequence, exclusive. If None, defaults to the value of `start` while the first entry of the range defaults to 0. |\n| `delta` | A 0-D `Tensor` (scalar). Number that increments `start`. Defaults to 1. |\n| `dtype` | The type of the elements of the resulting tensor. |\n| `name` | A name for the operation. Defaults to \"range\". |\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\n| Returns ------- ||\n|---|---|\n| An 1-D `Tensor` of type `dtype`. ||\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nnumpy compatibility\n-------------------\n\n\u003cbr /\u003e\n\nEquivalent to np.arange\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e"]]