clip(x, xmin, xmax, dtype=None)¶
Clips (limits) the values in an array.
Given an interval, values outside the interval are clipped to the interval edges. For example, if an interval of \([0, 1]\) is specified, values smaller than 0 become 0, and values larger than 1 become 1.
x (Tensor) – Tensor containing elements to clip.
xmax (Tensor, scalar, None) – Maximum value. If None, clipping is not performed on upper interval edge. Not more than one of xmin and xmax may be None. If xmin or xmax are tensors, then the three tensors will be broadcasted to match their shapes.
mindspore.dtype, optional) – defaults to None. Overrides the dtype of the output Tensor.
Tensor, a tensor with the elements of x, but where values < xmin are replaced with xmin, and those > xmax with xmax.
- Supported Platforms:
>>> import mindspore.numpy as np >>> x = np.asarray([1, 2, 3, -4, 0, 3, 2, 0]) >>> output = np.clip(x, 0, 2) >>> print(output) [1 2 2 0 0 2 2 0]