mindspore.ops.ScatterNdMin
- class mindspore.ops.ScatterNdMin(use_locking=False)[source]
Applies sparse minimum to individual values or slices in a tensor.
Using given values to update tensor value through the minimum operation, along with the input indices. This operation outputs the input_x after the update is done, which makes it convenient to use the updated value.
Refer to
mindspore.ops.scatter_nd_min()
for more details.- Parameters
use_locking (bool, optional) – Whether to protect the assignment by a lock. Default: False.
- Inputs:
input_x (Parameter) -The target tensor, with data type of Parameter.
indices (Tensor) - The index to do minimum operation whose data type must be int32 or int64. The rank of indices must be at least 2 and indices.shape[-1] <= len(shape).
updates (Tensor) - The tensor to do the max operation with input_x. The data type is same as input_x, and the shape is indices.shape[:-1] + x.shape[indices.shape[-1]:].
- Outputs:
Tensor, the updated input_x, has the same shape and type as input_x.
- Supported Platforms:
Ascend
GPU
CPU
Examples
>>> input_x = Parameter(Tensor(np.ones(8) * 10, mindspore.float32), name="x") >>> indices = Tensor(np.array([[2], [4], [1], [7]]), mindspore.int32) >>> updates = Tensor(np.array([6, 7, 8, 9]), mindspore.float32) >>> use_locking = False >>> scatter_nd_min = ops.ScatterNdMin(use_locking) >>> output = scatter_nd_min(input_x, indices, updates) >>> print(output) [10. 8. 6. 10. 7. 10. 10. 9.] >>> input_x = Parameter(Tensor(np.ones((4, 4, 4)) * 10, 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) >>> use_locking = False >>> scatter_nd_min = ops.ScatterNdMin(use_locking) >>> output = scatter_nd_min(input_x, indices, updates) >>> print(output) [[[ 1 1 1 1] [ 2 2 2 2] [ 3 3 3 3] [ 4 4 4 4]] [[10 10 10 10] [10 10 10 10] [10 10 10 10] [10 10 10 10]] [[ 5 5 5 5] [ 6 6 6 6] [ 7 7 7 7] [ 8 8 8 8]] [[10 10 10 10] [10 10 10 10] [10 10 10 10] [10 10 10 10]]]