dpnp.clip

dpnp.clip(a, a_min, a_max, *, out=None, order='K', **kwargs)[source]

Clip (limit) the values in an array.

For full documentation refer to numpy.clip.

Parameters:
  • a ({dpnp.ndarray, usm_ndarray}) -- Array containing elements to clip.

  • a_min ({dpnp.ndarray, usm_ndarray, None}) -- Minimum and maximum value. If None, clipping is not performed on the corresponding edge. Only one of a_min and a_max may be None. Both are broadcast against a.

  • a_max ({dpnp.ndarray, usm_ndarray, None}) -- Minimum and maximum value. If None, clipping is not performed on the corresponding edge. Only one of a_min and a_max may be None. Both are broadcast against a.

  • out ({None, dpnp.ndarray, usm_ndarray}, optional) -- The results will be placed in this array. It may be the input array for in-place clipping. out must be of the right shape to hold the output. Its type is preserved.

  • order ({"C", "F", "A", "K", None}, optional) -- Memory layout of the newly output array, if parameter out is None. If order is None, the default value "K" will be used.

Returns:

out -- An array with the elements of a, but where values < a_min are replaced with a_min, and those > a_max with a_max.

Return type:

dpnp.ndarray

Limitations

Keyword argument kwargs is currently unsupported. Otherwise NotImplementedError exception will be raised.

Examples

>>> import dpnp as np
>>> a = np.arange(10)
>>> a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> np.clip(a, 1, 8)
array([1, 1, 2, 3, 4, 5, 6, 7, 8, 8])
>>> np.clip(a, 8, 1)
array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1])
>>> np.clip(a, 3, 6, out=a)
array([3, 3, 3, 3, 4, 5, 6, 6, 6, 6])
>>> a
array([3, 3, 3, 3, 4, 5, 6, 6, 6, 6])
>>> a = np.arange(10)
>>> a
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> min = np.array([3, 4, 1, 1, 1, 4, 4, 4, 4, 4])
>>> np.clip(a, min, 8)
array([3, 4, 2, 3, 4, 5, 6, 7, 8, 8])