Creates a sequence of numbers. 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`, `sta
(start, limit=None, delta=1, dtype=None, name="range")
| 1357 | |
| 1358 | @tf_export("range") |
| 1359 | def range(start, limit=None, delta=1, dtype=None, name="range"): # pylint: disable=redefined-builtin |
| 1360 | """Creates a sequence of numbers. |
| 1361 | |
| 1362 | Creates a sequence of numbers that begins at `start` and extends by |
| 1363 | increments of `delta` up to but not including `limit`. |
| 1364 | |
| 1365 | The dtype of the resulting tensor is inferred from the inputs unless |
| 1366 | it is provided explicitly. |
| 1367 | |
| 1368 | Like the Python builtin `range`, `start` defaults to 0, so that |
| 1369 | `range(n) = range(0, n)`. |
| 1370 | |
| 1371 | For example: |
| 1372 | |
| 1373 | ```python |
| 1374 | start = 3 |
| 1375 | limit = 18 |
| 1376 | delta = 3 |
| 1377 | tf.range(start, limit, delta) # [3, 6, 9, 12, 15] |
| 1378 | |
| 1379 | start = 3 |
| 1380 | limit = 1 |
| 1381 | delta = -0.5 |
| 1382 | tf.range(start, limit, delta) # [3, 2.5, 2, 1.5] |
| 1383 | |
| 1384 | limit = 5 |
| 1385 | tf.range(limit) # [0, 1, 2, 3, 4] |
| 1386 | ``` |
| 1387 | |
| 1388 | Args: |
| 1389 | start: A 0-D `Tensor` (scalar). Acts as first entry in the range if `limit` |
| 1390 | is not None; otherwise, acts as range limit and first entry defaults to 0. |
| 1391 | limit: A 0-D `Tensor` (scalar). Upper limit of sequence, exclusive. If None, |
| 1392 | defaults to the value of `start` while the first entry of the range |
| 1393 | defaults to 0. |
| 1394 | delta: A 0-D `Tensor` (scalar). Number that increments `start`. Defaults to |
| 1395 | 1. |
| 1396 | dtype: The type of the elements of the resulting tensor. |
| 1397 | name: A name for the operation. Defaults to "range". |
| 1398 | |
| 1399 | Returns: |
| 1400 | An 1-D `Tensor` of type `dtype`. |
| 1401 | |
| 1402 | @compatibility(numpy) |
| 1403 | Equivalent to np.arange |
| 1404 | @end_compatibility |
| 1405 | """ |
| 1406 | if limit is None: |
| 1407 | start, limit = 0, start |
| 1408 | |
| 1409 | with ops.name_scope(name, "Range", [start, limit, delta]) as name: |
| 1410 | start = ops.convert_to_tensor(start, dtype=dtype, name="start") |
| 1411 | limit = ops.convert_to_tensor(limit, dtype=dtype, name="limit") |
| 1412 | delta = ops.convert_to_tensor(delta, dtype=dtype, name="delta") |
| 1413 | |
| 1414 | # infer dtype if not explicitly provided |
| 1415 | if dtype is None: |
| 1416 | dtype_hierarchy = [ |