mindspore.ops.scatter_update
- mindspore.ops.scatter_update(input_x, indices, updates)[源代码]
根据指定输入索引和更新值更新输入tensor的值。
说明
支持隐式类型转换、类型提升。
因Parameter对象不支持类型转换,当 input_x 为低精度数据类型时,会抛出异常。
参数 updates 的shape为 indices.shape + input_x.shape[1:] 。
若 indices 的shape为(i, …, j),则
- 参数:
input_x (Union[Parameter, Tensor]) - 输入的parameter或tensor。
indices (Tensor) - 更新操作的索引。如果索引中存在重复项,则更新的顺序无法得知。
updates (Tensor) - 更新值。
- 返回:
Tensor
- 支持平台:
Ascend
GPU
CPU
样例:
>>> import mindspore >>> np_x = mindspore.tensor([[-0.1, 0.3, 3.6], [0.4, 0.5, -3.2]], mindspore.float32) >>> input_x = mindspore.Parameter(np_x, name="x") >>> indices = mindspore.tensor([0, 1], mindspore.int32) >>> np_updates = mindspore.tensor([[2.0, 1.2, 1.0], [3.0, 1.2, 1.0]]) >>> updates = mindspore.tensor(np_updates, mindspore.float32) >>> output = mindspore.ops.scatter_update(input_x, indices, updates) >>> print(output) [[2. 1.2 1.] [3. 1.2 1.]]