index_put

paddle. index_put ( x, indices, value, accumulate=False, name=None ) [source]

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

Examples

import paddle

x = paddle.zeros([3, 3])
value = paddle.ones([3])
ix1 = paddle.to_tensor([0,1,2])
ix2 = paddle.to_tensor([1,2,1])
indices=(ix1,ix2)

out = paddle.index_put(x,indices,value)
print(x)
# Tensor(shape=[3, 3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
#        [[0., 0., 0.],
#         [0., 0., 0.],
#         [0., 0., 0.]])
print(out)
# Tensor(shape=[3, 3], dtype=float32, place=Place(gpu:0), stop_gradient=True,
#        [[0., 1., 0.],
#         [0., 0., 1.],
#         [0., 1., 0.]])