megengine.functional.linspace#

linspace(start, stop, num, *, dtype='float32', device=None)[源代码]#

返回指定区间内均匀分布的数字。

返回计算区间在 [start, stop]``的``num 个均匀分布的样本。

参数:
  • start (Number) – 区间的开始

  • stop (Number) – 区间的终点

  • num (int) – 将要产生的值的个数。

关键字参数:
  • dtype (Tensor.dtype, optional) – 输出tensor的数据类型。如果 dtype 没有给出,则从 startstop 来推断。

  • device (Tensor.device, optional) – 被创建的向量所处的设备

返回类型:

Tensor

返回:

包含均匀间隔值的一维 tensor。

参见

arange

实际案例

>>> F.linspace(1, 10, 10)
Tensor([ 1.  2.  3.  4.  5.  6.  7.  8.  9. 10.], device=xpux:0)
>>> F.linspace(2., 3., 5)
Tensor([2.   2.25 2.5  2.75 3.  ], device=xpux:0)