oneflow.slice_update

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

Update a slice of tensor x. Like x[start:stop:step] = update.

Parameters
  • x – A Tensor, whose slice will be updated.

  • update – A Tensor, indicate the update content.

  • 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.array([1, 1, 1, 1, 1]).astype(np.float32))
>>> update = flow.Tensor(np.array([2, 3, 4]).astype(np.float32))
>>> flow.slice_update(input, update, slice_tup_list=[[1, 4, 1]])
tensor([1., 2., 3., 4., 1.], dtype=oneflow.float32)