oneflow.narrow

oneflow.narrow(x, dim: int, start: int, length: int)Tensor

Returns a new tensor that is a narrowed version of input tensor. The dimension dim is input from start to start + length.

Parameters
  • input – the tensor to narrow.

  • dim – the dimension along which to narrow.

  • start – the starting dimension.

  • length – the distance to the ending dimension.

For example:

>>> import oneflow as flow
>>> input = flow.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> flow.narrow(input, 0, 0, 2)
tensor([[1, 2, 3],
        [4, 5, 6]], dtype=oneflow.int64)
>>> flow.narrow(input, 1, 1, 2)
tensor([[2, 3],
        [5, 6],
        [8, 9]], dtype=oneflow.int64)