select_scatter

paddle. select_scatter ( x: Tensor, values: Tensor, axis: int, index: int, name: str | None = None ) → Tensor [source]

Embeds the values of the values tensor into x at the given index of axis.

Parameters
  • x (Tensor) – The Destination Tensor. Supported data types are bool, float16, float32, float64, uint8, int8, int16, int32, int64, bfloat16, complex64, complex128. Alias: input.

  • values (Tensor) – The tensor to embed into x. Supported data types are bool, float16, float32, float64, uint8, int8, int16, int32, int64, bfloat16, complex64, complex128. Alias: src.

  • axis (int) – the dimension to insert the slice into. Alias: dim.

  • index (int) – the index to select with.

  • name (str|None, optional) – Name for the operation (optional, default is None).

Returns

Tensor, same dtype and shape with x

Examples

>>> import paddle

>>> x = paddle.zeros((2, 3, 4)).astype("float32")
>>> values = paddle.ones((2, 4)).astype("float32")
>>> res = paddle.select_scatter(x, values, 1, 1)
>>> print(res)
Tensor(shape=[2, 3, 4], dtype=float32, place=Place(cpu), stop_gradient=True,
[[[0., 0., 0., 0.],
  [1., 1., 1., 1.],
  [0., 0., 0., 0.]],
 [[0., 0., 0., 0.],
  [1., 1., 1., 1.],
  [0., 0., 0., 0.]]])