mindspore.ops.arange
- mindspore.ops.arange(start=0, stop=None, step=1, rtype=None)[source]
Returns evenly spaced values within a given interval.
- Parameters
start (Union[int, float]) – Start value of interval. The interval includes this value. When stop is None, start must be greater than 0, and the interval is \([0, start)\). When stop is not None, start must be less than stop.
stop (Union[int, float], optional) – End value of interval. The interval does not include this value. Default is None.
step (Union[int, float], optional) – Spacing between values. For any output out, this is the distance between two adjacent values, \(out[i+1] - out[i]\). The default step size is 1. If step is specified as a position argument, start must also be given.
rtype (Union[
mindspore.dtype
, str], optional) – Designated tensor type. If rtype is None, the data type of the new tensor will be inferred from start, stop and step. Default is None.
- Returns
Tensor with evenly spaced values.
- Raises
TypeError – If input arguments have types not specified above.
ValueError – If input arguments have values not specified above.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore.ops as ops >>> print(ops.arange(0, 5, 1)) [0 1 2 3 4] >>> print(ops.arange(3)) [0 1 2] >>> print(ops.arange(start=0, stop=3)) [0 1 2] >>> print(ops.arange(0, stop=3, step=0.5)) [0. 0.5 1. 1.5 2. 2.5]