mindspore.ops.AssignSub

View Source On Gitee
class mindspore.ops.AssignSub[source]

Updates a Parameter by subtracting a value from it.

Refer to mindspore.ops.assign_sub() for more details.

Inputs:
  • variable (Parameter) - The Parameter. \((N,*)\) where \(*\) means, any number of additional dimensions, its rank be should be less than 8.

  • value (Union[numbers.Number, Tensor]) - The value to be subtracted from the variable. It must have the same shape as variable if it is a Tensor.

Outputs:

Tensor, has the same data type and shape as original variable.

Supported Platforms:

Ascend GPU CPU

Examples

>>> import mindspore
>>> import numpy as np
>>> from mindspore import Tensor, ops, nn
>>> from mindspore.common.initializer import initializer
>>> class Net(nn.Cell):
...     def __init__(self):
...         super(Net, self).__init__()
...         self.AssignSub = ops.AssignSub()
...         self.variable = mindspore.Parameter(initializer(1, [1], mindspore.int32), name="global_step")
...
...     def construct(self, x):
...         self.AssignSub(self.variable, x)
...         return self.variable
...
>>> net = Net()
>>> value = Tensor(np.ones([1]).astype(np.int32)*100)
>>> output = net(value)
>>> print(net.variable.asnumpy())
[-99]