代码拉取完成,页面将自动刷新
tf.compat.v1.assign_sub(ref, value, use_locking=None, name=None) -> Tensor
For more information, see tf.compat.v1.assign_sub.
mindspore.ops.assign_sub(variable, value)-> Tensor
For more information, see mindspore.ops.assign_sub.
TensorFlow: Update the network parameters by subtracting a specific value from the network parameters, and return a Tensor with the same type as ref.
MindSpore: MindSpore API implements the same functions as TensorFlow, with some different parameter names.
Categories | Subcategories | TensorFlow | MindSpore | Differences |
---|---|---|---|---|
Parameters | Parameter 1 | ref | variable | Same function, different parameter names |
Parameter 2 | value | value | - | |
Parameter 3 | use_locking | - | In TensorFlow, whether to use locks in update operations. Default value: False. | |
Parameter 4 | name | - | Not involved |
The outputs of MindSpore and TensorFlow are consistent.
# TensorFlow
import tensorflow as tf
import numpy as np
variable = tf.Variable(np.array([[2.4, 1], [0.1, 6]]), dtype=tf.float32)
value = tf.constant(np.array([[-2, 3], [3.6, 1]]), dtype=tf.float32)
out = tf.compat.v1.assign_sub(variable, value)
print(out.numpy())
# [[ 4.4 -2. ]
# [-3.5 5. ]]
# MindSpore
import mindspore
import numpy as np
from mindspore.ops import function as ops
from mindspore import Tensor
variable = Tensor(np.array([[2.4, 1], [0.1, 6]]), mindspore.float32)
value = Tensor(np.array([[-2, 3], [3.6, 1]]), mindspore.float32)
out = ops.assign_sub(variable, value)
print(out)
# [[ 4.4 -2. ]
# [-3.5 5. ]]
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。