clip
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.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
|
required | |
a_min
|
scalar or `SparseArray` or `None`
|
Minimum value. If |
None
|
a_max
|
scalar or `SparseArray` or `None`
|
Maximum value. If |
None
|
out
|
SparseArray
|
If provided, the results will be placed in this array. It may be
the input array for in-place clipping. |
None
|
Returns:
Name | Type | Description |
---|---|---|
clipped_array |
SparseArray
|
An array with the elements of |
Examples:
>>> import sparse
>>> x = sparse.COO.from_numpy([0, 0, 0, 1, 2, 3])
>>> sparse.clip(x, a_min=1).todense()
array([1, 1, 1, 1, 2, 3])
>>> sparse.clip(x, a_max=1).todense()
array([0, 0, 0, 1, 1, 1])
>>> sparse.clip(x, a_min=1, a_max=2).todense()
array([1, 1, 1, 1, 2, 2])
See Also
numpy.clip : Equivalent NumPy function
Source code in sparse/numba_backend/_coo/common.py
1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 |
|