mindspore.mint.arange
- mindspore.mint.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], optional) – The start of the interval. Default:
0
.end (Union[float, int], optional) – The end of the interval, exclusive. Default:
None
. IfNone
, it defaults to the value of start, and 0 is used as the starting value.step (Union[float, int], optional) – The step size with which the array element increments. 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, cast to dtype if provided, may potentially lose precision due to casting.
- Raises
TypeError – If start, end or step are not of type int or float.
ValueError – If step = 0.
ValueError – If start >= end when step > 0.
ValueError – If start <= end when step < 0.
- Supported Platforms:
Ascend
Examples
>>> import mindspore as ms >>> from mindspore import Tensor, mint >>> output = mint.arange(1, 6) >>> print(output) [1 2 3 4 5] >>> print(output.dtype) Int64 >>> output = mint.arange(0, 3, 1.2) >>> print(output) [0. 1.2 2.4] >>> print(output.dtype) Float32 >>> output = mint.arange(7, 1, -2) >>> print(output) [7 5 3] >>> print(output.dtype) Int64 >>> output = mint.arange(12, 2, -1, dtype=ms.bfloat16) >>> print(output) [12. 11. 10. 9. 8. 7. 6. 5. 4. 3.] >>> print(output.dtype) BFloat16