megengine.functional.arange

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

返回半开区间 [start, stop) 内均匀间隔的值组成的1维Tensor。

注解

step 不是整数且浮点舍入误差影响了输出Tensor长度的情况下,本函数无法保证区间中不包含 stop 值。

参数
  • start (Number) – 如果 stop 被指定了, 该值表示区间的开始(区间包含该值);否则该值表示区间的结束(区间不包含该值)。如果 stop 没有被指定, 默认的区间开始值是 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 .

关键字参数
  • dtype (Tensor.dtype, optional) – output tensor data type.

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

参见

linspace

返回类型

Tensor

返回

由均匀间隔的值组成的1维tensor。在 stop - startstep 符号相同时输出 tensor 的长度是 ceil((stop-start)/step),其它情况下是0。

实际案例

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