mindspore.Tensor.clip

查看源文件
mindspore.Tensor.clip(min=None, max=None)

mindspore.Tensor.clamp() 的别名。

支持平台:

Ascend GPU CPU

样例:

>>> # case 1: the data type of input is number
>>> import mindspore
>>> from mindspore import Tensor
>>> import numpy as np
>>> min_value = 5
>>> max_value = 20
>>> input = Tensor(np.array([[1., 25., 5., 7.], [4., 11., 6., 21.]]), mindspore.float32)
>>> output = input.clip(min_value, max_value)
>>> print(output)
[[ 5. 20.  5.  7.]
[ 5. 11.  6. 20.]]