COO.clip(min=None, max=None, out=None)[source]

Clip (limit) the values in the array.

Return an array whose values are limited to [min, max]. One of min or max must be given.

  • min (scalar or array_like or None) – Minimum value. If None, clipping is not performed on lower interval edge.

  • max (scalar or array_like or None) – Maximum value. If None, clipping is not performed on upper interval edge.

  • out (COO, optional) – If provided, 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.


clipped_array – An array with the elements of self, but where values < min are replaced with min, and those > max with max.

Return type



>>> x = COO.from_numpy([0, 0, 0, 1, 2, 3])
>>> x.clip(min=1).todense()  
array([1, 1, 1, 1, 2, 3])
>>> x.clip(max=1).todense()  
array([0, 0, 0, 1, 1, 1])
>>> x.clip(min=1, max=2).todense() 
array([1, 1, 1, 1, 2, 2])