megengine.functional.arange

arange(start=0, stop=None, step=1, *, dtype='float32', device=None)[source]

Returns evenly spaced values within the half-open interval [start, stop) as a one-dimensional tensor.

Note

This function cannot guarantee that the interval does not include the stop value in those cases where step is not an integer and floating-point rounding errors affect the length of the output tensor.

Parameters
  • start (Number) – if stop is specified, the start of interval (inclusive); otherwise, the end of the interval (exclusive). If stop is not specified, the default starting value is 0.

  • stop (Number) – the end of the interval.

  • step (Number) – the distance between two adjacent elements ( out[i+1] - out[i] ). Must not be 0 ; may be negative, this results i an empty tensor if stop >= start .

Keyword Arguments
  • dtype (Tensor.dtype, optional) – output tensor data type.

  • device (Tensor.device, optional) – device on which to place the created tensor.

See also

linspace

Return type

Tensor

Returns

A one-dimensional tensor containing evenly spaced values.

The length of the output tensor must be ceil((stop-start)/step) if stop - start and step have the same sign, and length 0 otherwise.

Examples

>>> F.arange(5)
Tensor([0. 1. 2. 3. 4.], device=xpux:0)
>>> F.arange(1, 4)
Tensor([1. 2. 3.], device=xpux:0)