oneflow.slice

oneflow.slice(input, slice_tup_list: Sequence[Tuple[int, int, int]])

Extracts a slice from a tensor. The slice_tup_list assigns the slice indices in each dimension, the format is (start, stop, step). The operator will slice the tensor according to the slice_tup_list.

Parameters
  • input – A Tensor.

  • slice_tup_list – A list of slice tuple, indicate each dimension slice (start, stop, step).

For example:

>>> import numpy as np
>>> import oneflow as flow
>>> input = flow.Tensor(np.random.randn(3, 6, 9).astype(np.float32))
>>> tup_list = [[None, None, None], [0, 5, 2], [0, 6, 3]]
>>> y = flow.slice(input, slice_tup_list=tup_list)
>>> y.shape
oneflow.Size([3, 3, 2])