mindspore.ops.slice_scatter

View Source On Gitee
mindspore.ops.slice_scatter(input, src, axis=0, start=None, end=None, step=1)[source]

Slice the input Tensor in the specified dimension and overlay the slice results with the source Tensor. The input is sliced along the specified dimension. The start position of the slice is start , the end position is end , and the step size is step . Then the slicing result is overwritten with src to get the output Tensor.

Parameters
  • input (Tensor) – The target Tensor.

  • src (Tensor) – The source Tensor.

  • axis (int, optional) – The dimension of input to be sliced. Default: 0 .

  • start (int, optional) – The start index to slice in the specified dimension. Default: None, start is 0 .

  • end (int, optional) – The end index to slice in the specified dimension. Default: None, end is the length of input in the specified dimension.

  • step (int, optional) – Step size. Default: 1, the distance from the next slice element is 1 .

Returns

Tensor after embedding, has the same shape and type as input .

Raises
  • ValueError – The shape of src is not the same as the shape of input slice.

  • TypeError – If input is not a Tensor.

  • TypeError – If src is not a Tensor.

  • TypeError – If axis or step is not an integer.

  • TypeError – If start or end is not None or an integer.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore as ms
>>> a = ms.ops.zeros((4, 6))
>>> b = ms.ops.ones((4, 3))
>>> output = ms.ops.slice_scatter(a, b, axis=1, start=0, end=5, step=2)
>>> print(output)
[[1. 0. 1. 0. 1. 0.]
 [1. 0. 1. 0. 1. 0.]
 [1. 0. 1. 0. 1. 0.]
 [1. 0. 1. 0. 1. 0.]]