mindspore.ops.index_fill
- mindspore.ops.index_fill(x, axis, index, value)[源代码]
按照指定轴和索引用输入 value 填充输入 x 的元素。
- 参数:
x (Tensor) - 输入tensor。
axis (Union[int, Tensor]) - 指定轴。
index (Tensor) - 指定索引。
value (Union[bool, int, float, Tensor]) - 填充输入tensor的值。
- 返回:
Tensor
- 支持平台:
Ascend
GPU
CPU
样例:
>>> import mindspore >>> x = mindspore.tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], mindspore.float32) >>> index = mindspore.tensor([0, 2], mindspore.int32) >>> value = mindspore.tensor(-2.0, mindspore.float32) >>> y = mindspore.ops.index_fill(x, 1, index, value) >>> print(y) [[-2. 2. -2.] [-2. 5. -2.] [-2. 8. -2.]]