mindspore.ops.arange
- mindspore.ops.arange(start=0, end=None, step=1, *, dtype=None)[source]
Creates a sequence of numbers that begins at start and extends by increments of step up to but not including end.
- Parameters
start (Union[float, int, Tensor], optional) – The start of the interval. If Tensor, the shape must be \(()\) . Default:
0
.end (Union[float, int, Tensor], optional) – The end of the interval, exclusive. If Tensor, the shape must be \(()\). Default:
None
. IfNone
, it defaults to the value of start, and 0 is used as the starting value.step (Union[float, int, Tensor], optional) – Number that increments start. If Tensor, the shape must be \(()\). Default:
1
.
- Keyword Arguments
dtype (mindspore.dtype, optional) –
The required data type of returned Tensor. Default:
None
. When dtype is not specified orNone
:If start, end, and step are all integers, the dtype of output is int64,
If start, end, and step contain at least one floating-point number, the dtype of output is float32.
- Returns
A 1-D Tensor, with the same type as the inputs.
- Raises
TypeError – If start, end or step is not an int or a float or a TensorScalar(Special Tensor with shape ()) in valid dtypes.
ValueError – If step = 0.
ValueError – If start >= end when step > 0.
ValueError – If start <= end when step < 0.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore as ms >>> from mindspore import Tensor, ops >>> output = ops.arange(1, 6) >>> print(output) [1 2 3 4 5] >>> print(output.dtype) Int64 >>> output = ops.arange(0, 3, 1.2) >>> print(output) [0. 1.2 2.4] >>> print(output.dtype) Float32 >>> output = ops.arange(7, 1, -2) >>> print(output) [7 5 3] >>> print(output.dtype) Int64 >>> output = ops.arange(ms.Tensor(12.0, dtype=ms.float64), 2, ms.Tensor(-1.0, dtype=ms.float32)) >>> print(output) [12. 11. 10. 9. 8. 7. 6. 5. 4. 3.] >>> print(output.dtype) Float32