index_fill¶
Outplace 版本的 index_fill_ API
代码示例¶
>>> 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]])
更多关于 outplace 操作的介绍请参考 3.1.3 原位(Inplace)操作和非原位(Outplace)操作的区别 了解详情。