mindspore.ops.ScatterSub
- class mindspore.ops.ScatterSub(*args, **kwargs)[source]
Updates the value of the input tensor through the subtraction operation.
Using given values to update tensor value through the subtraction 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.
for each i, …, j in indices.shape:
\[\text{input_x}[\text{indices}[i, ..., j], :] \mathrel{-}= \text{updates}[i, ..., j, :]\]Inputs of input_x and updates comply with the implicit type conversion rules to make the data types consistent. If they have different data types, lower priority data type will be converted to relatively highest priority data type. RuntimeError exception will be thrown when the data type conversion of Parameter is required.
- Parameters
use_locking (bool) – Whether protect the assignment by a lock. Default: False.
- Inputs:
input_x (Parameter) - The target parameter.
indices (Tensor) - The index to perform the subtraction operation whose data type must be mindspore.int32.
updates (Tensor) - The tensor that performs the subtraction operation with input_x, the data type is the same as input_x, the shape is indices_shape + x_shape[1:].
- Outputs:
Parameter, the updated input_x.
- Raises
TypeError – If use_locking is not a bool.
- Supported Platforms:
Ascend
Examples
>>> input_x = Parameter(Tensor(np.array([[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]]), mindspore.float32), name="x") >>> indices = Tensor(np.array([[0, 1]]), mindspore.int32) >>> updates = Tensor(np.array([[[1.0, 1.0, 1.0], [2.0, 2.0, 2.0]]]), mindspore.float32) >>> scatter_sub = ops.ScatterSub() >>> output = scatter_sub(input_x, indices, updates) >>> print(output) [[-1. -1. -1.] [-1. -1. -1.]]