index_put

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

Outplace 版本的 index_put_ API

代码示例

>>> 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(cpu), stop_gradient=True,
[[0., 0., 0.],
 [0., 0., 0.],
 [0., 0., 0.]])
>>> print(out)
Tensor(shape=[3, 3], dtype=float32, place=Place(cpu), stop_gradient=True,
[[0., 1., 0.],
 [0., 0., 1.],
 [0., 1., 0.]])

更多关于 outplace 操作的介绍请参考 3.1.3 原位(Inplace)操作和非原位(Outplace)操作的区别 了解详情。