mindspore.numpy.arange
- mindspore.numpy.arange(start, stop=None, step=None, dtype=None)[source]
Returns evenly spaced values within a given interval.
- Parameters
start (Union[int, float]) – Start of interval. The interval includes this value. When stop is provided as a position argument, start must be given, when stop is a normal argument, start can be optional, and default is 0. Please see additional examples below.
stop (Union[int, float], optional) – End of interval. The interval does not include this value, except in some cases where step is not an integer and floating point round-off affects the length of out.
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.
dtype (Union[
mindspore.dtype
, str], optional) – Designated tensor dtype. If dtype 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(PyNative Mode) – If input arguments have types not specified above, or arguments are not given in the correct orders specified above.
RuntimeError(Graph Mode) – The inputs that lead to TypeError in Pynative Mode will lead to RuntimeError in Graph Mode.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> import mindspore.numpy as np >>> print(np.arange(0, 5, 1)) [0 1 2 3 4] >>> print(np.arange(3)) [0 1 2] >>> print(np.arange(start=0, stop=3)) [0 1 2] >>> print(np.arange(0, stop=3, step=0.5)) [0. 0.5 1. 1.5 2. 2.5] >>> print(np.arange(stop=3)) # This will lead to TypeError