index_fill

paddle. index_fill ( x, index, axis, value, name=None ) [source]

Outplace version of index_fill_ API, the output Tensor will be inplaced with input x. Please refer to index_fill_.

Examples

>>> import paddle
>>> input_tensor = paddle.to_tensor([[1, 2, 3], [4, 5, 6], [7, 8, 9]], dtype='int64')
>>> index = paddle.to_tensor([0, 2], dtype="int32")
>>> value = -1
>>> res = paddle.index_fill(input_tensor, index, 0, value)
>>> print(input_tensor)
Tensor(shape=[3, 3], dtype=int64, place=Place(gpu:0), stop_gradient=True,
       [[1, 2, 3],
        [4, 5, 6],
        [7, 8, 9]])
>>> print(res)
Tensor(shape=[3, 3], dtype=int64, place=Place(gpu:0), stop_gradient=True,
       [[-1, -1, -1],
        [ 4,  5,  6],
        [-1, -1, -1]])