sciPy function stats.threshold () | python

scipy.stats.threshold (a, threshmin = None, threshmax = None, newval = 0) truncates the array array. Out-of-range values ​​can be overridden by the 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: Work

# stats.threshold () method

import numpy as np

from scipy import stats

 

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

  

 

print ( " arr1: " , arr1)

  

print ( "clipped arr1:" , stats.threshold (

  arr1, threshmin = 2 , threshma x = 8 , newval = - 1 ))

Output:

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