mindspore.ops.ScatterNdMul
- class mindspore.ops.ScatterNdMul[源代码]
对张量中的单个值或切片应用sparse multiplication。
使用给定值通过乘法运算和输入索引更新Parameter值。在更新完成后输出 input_x ,这有利于更加方便地使用更新后的值。
更多参考详见
mindspore.ops.scatter_nd_mul()
。- 支持平台:
GPU
CPU
样例:
>>> input_x = Parameter(Tensor(np.array([1, 2, 3, 4, 5, 6, 7, 8]), mindspore.float32), name="x") >>> indices = Tensor(np.array([[2], [4], [1], [7]]), mindspore.int32) >>> updates = Tensor(np.array([6, 7, 8, 9]), mindspore.float32) >>> scatter_nd_mul = ops.ScatterNdMul() >>> output = scatter_nd_mul(input_x, indices, updates) >>> print(output) [ 1. 16. 18. 4. 35. 6. 7. 72.] >>> input_x = Parameter(Tensor(np.ones((4, 4, 4)), mindspore.int32)) >>> indices = Tensor(np.array([[0], [2]]), mindspore.int32) >>> updates = Tensor(np.array([[[1, 1, 1, 1], [2, 2, 2, 2], [3, 3, 3, 3], [4, 4, 4, 4]], ... [[5, 5, 5, 5], [6, 6, 6, 6], [7, 7, 7, 7], [8, 8, 8, 8]]]), mindspore.int32) >>> scatter_nd_mul = ops.ScatterNdMul() >>> output = scatter_nd_mul(input_x, indices, updates) >>> print(output) [[[1 1 1 1] [2 2 2 2] [3 3 3 3] [4 4 4 4]] [[1 1 1 1] [1 1 1 1] [1 1 1 1] [1 1 1 1]] [[5 5 5 5] [6 6 6 6] [7 7 7 7] [8 8 8 8]] [[1 1 1 1] [1 1 1 1] [1 1 1 1] [1 1 1 1]]]