mindspore.ops.arange

查看源文件
mindspore.ops.arange(start=0, end=None, step=1, *, dtype=None)[源代码]

返回一个在 [ start, end ) 区间内,步长为 step 的tensor。

参数:
  • start (Union[float, int, Tensor], 可选) - 区间的起始值。默认 0

  • end (Union[float, int, Tensor], 可选) - 区间的末尾值。默认 None 表示为 start 的值,同时将 0 作为区间的起始值。

  • step (Union[float, int, Tensor], 可选) - 值的间隔。默认 1

关键字参数:
  • dtype (mindspore.dtype, 可选) - 指定的数据类型。默认 None

返回:

Tensor

支持平台:

Ascend GPU CPU

样例:

>>> import mindspore
>>> mindspore.ops.arange(4)
Tensor(shape=[4], dtype=Int64, value= [0, 1, 2, 3])
>>> mindspore.ops.arange(1, 6)
Tensor(shape=[5], dtype=Int64, value= [1, 2, 3, 4, 5])
>>> mindspore.ops.arange(0, 2, 0.5)
Tensor(shape=[4], dtype=Float32, value= [ 0.00000000e+00,  5.00000000e-01,  1.00000000e+00,  1.50000000e+00])