tf.clip_by_value(t, clip_value_min, clip_value_max, name=None) -> Tensor
For more information, see tf.clip_by_value.
mindspore.ops.clip_by_value(x, clip_value_min=None, clip_value_max=None) -> Tensor
For more information, see mindspore.ops.clip_by_value.
TensorFlow: Given a tensor t, this operation returns a tensor of the same type and shape as t. Any value less than clip_value_min in t is set to clip_value_min, and any value greater than clip_value_max is set to clip_value_max. When clip_value_min is greater than clip_value_max, the value of the tensor will be set to clip_value_min.
MindSpore: When clip_value_min is less than or equal to clip_value_max, MindSpore API implements the same function as TensorFlow. When clip_value_min is greater than clip_value_max, the value of the tensor element will be set to clip_value_max.
Categories | Subcategories | TensorFlow | MindSpore | Differences |
---|---|---|---|---|
Parameters | Parameter 1 | t | x | Same function, different parameter names |
Parameter 2 | clip_value_min | clip_value_min | - | |
Parameter 3 | clip_value_max | clip_value_max | - | |
Parameter 4 | name | - | Not involved |
When clip_value_min is less than or equal to clip_value_max, the two APIs achieve the same function and have the same usage.
# TensorFlow
import tensorflow as tf
t = tf.constant([[1., 25., 5., 7.], [4., 11., 6., 21.]])
t2 = tf.clip_by_value(t, clip_value_min=5, clip_value_max=22)
print(t2.numpy())
#[[ 5. 22. 5. 7.]
# [ 5. 11. 6. 21.]]
# MindSpore
import mindspore
from mindspore import Tensor, ops
import numpy as np
input = Tensor(np.array([[1., 25., 5., 7.], [4., 11., 6., 21.]]), mindspore.float32)
output = ops.clip_by_value(input, clip_value_min=5, clip_value_max=22)
print(output)
#[[ 5. 22. 5. 7.]
# [ 5. 11. 6. 21.]]
When clip_value_min is greater than clip_value_max, TensorFlow will set the value of the tensor to clip_value_min and MindSpore will set it to clip_value_max.
# TensorFlow
import tensorflow as tf
t = tf.constant([[1., 25., 5., 7.], [4., 11., 6., 21.]])
t2 = tf.clip_by_value(t, clip_value_min=22, clip_value_max=5)
print(t2.numpy())
#[[ 22. 22. 22. 22.]
# [ 22. 22. 22. 22.]]
# MindSpore
import mindspore
from mindspore import Tensor, ops
import numpy as np
input = Tensor(np.array([[1., 25., 5., 7.], [4., 11., 6., 21.]]), mindspore.float32)
output = ops.clip_by_value(input, clip_value_min=22, clip_value_max=5)
print(output)
#[[ 5. 5. 5. 5.]
# [ 5. 5. 5. 5.]]
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。