oneflow.arange

oneflow.arange(start: int = 0, end, step: int = 1, dtype: Optional[oneflow._oneflow_internal.dtype] = None, device: Optional[Union[oneflow._oneflow_internal.device, str]] = None, placement: Optional[oneflow._oneflow_internal.placement] = None, sbp: Optional[Union[oneflow._oneflow_internal.sbp.sbp, List[oneflow._oneflow_internal.sbp.sbp]]] = None, requires_grad: bool = False)

Returns a 1-D tensor of size \(\left\lfloor \frac{\text{end} - \text{start}}{\text{step}} \right\rfloor + 1\) with values from start to end with step step. Step is the gap between two values in the tensor.

\[\text{out}_{i+1} = \text{out}_i + \text{step}.\]
Parameters
  • start (int) – the starting value for the set of points. Default: 0.

  • end (int) – the ending value for the set of points

  • step (int) – the gap between each pair of adjacent points. Default: 1.

Keyword Arguments
  • dtype (flow.dtype, optional) – If dtype is not given, infer the dtype from the other input arguments. If any of start, end, or step are floating-point, the dtype is inferred to be the floating-point data type. Otherwise, the dtype is inferred to be flow.int64.

  • device (flow.device, optional) – the desired device of returned tensor. Default: if None, uses the current device for the default tensor.

  • requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.

For example:

>>> import oneflow as flow

>>> y = flow.arange(0, 5)
>>> y
tensor([0, 1, 2, 3, 4], dtype=oneflow.int64)