mindspore.ops.IndexFill

class mindspore.ops.IndexFill[source]

Fills the elements under the dim dimension of the input Tensor x with the input value by selecting the indices in the order given in index.

Warning

This is an experimental API that is subject to change or deletion.

Refer to mindspore.ops.index_fill() for more details.

Inputs:
  • x (Tensor) - Input tensor.

  • dim (Union[int, Tensor]) - Dimension along which to fill the input tensor. Only supports a 0-dimensional tensor or an int number.

  • index (Tensor) - Indices of the input tensor to fill in.

  • value (Union[bool, int, float, Tensor]) - Value to fill the input tensor.

Outputs:

Tensor, has the same type and shape as input tensor.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> index_fill = ops.IndexFill()
>>> x = Tensor(np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]).astype(np.float32))
>>> index = Tensor([0, 2], mindspore.int32)
>>> value = Tensor(-2.0, mindspore.float32)
>>> y = index_fill(x, 1, index, value)
>>> print(y)
[[-2. 2. -2.]
 [-2. 5. -2.]
 [-2. 8. -2.]]