sciPy stats.threshold() function | Python

scipy.stats.threshold(a, threshmin=None, threshmax=None, newval=0) function clips the give array. Values off the set limits can be replaced by ‘newval’ parameter.

Parameters :
arr : [array_like] Input array or object to clip.
threshmin : (float, int) Minimum threshold. By default is None
threshmax : (float, int) Maximum threshold. By default is None
newval : (float, int) Value to put in place of values(that are out of the limits).

Results : Clipped array with values(off the limits) replaced by newval.

Code #1: Working

filter_none

edit
close

play_arrow

link
brightness_4
code

# stats.threshold() method  
import numpy as np
from scipy import stats
   
arr1 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  
  
print ("\narr1 : ", arr1)
  
print ("\nclipped arr1 : \n", stats.threshold(
        arr1, threshmin = 2, threshmax = 8, newval =-1))

chevron_right


Output :

arr1 :  [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

clipped arr1 : 
[-1 -1 2 3 4 5 6 7 8 -1]
My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.