def trim_mean(a, proportiontocut, axis=0):
 a = np.asarray(a)
 if (a.size == 0):
  return np.nan
 if (axis is None):
  a = a.ravel()
  axis = 0
 nobs = a.shape[axis]
 lowercut = int((proportiontocut * nobs))
 uppercut = (nobs - lowercut)
 if (lowercut > uppercut):
  raise ValueError('Proportion too big.')
 atmp = np.partition(a, (lowercut, (uppercut - 1)), axis)
 sl = ([slice(None)] * atmp.ndim)
 sl[axis] = slice(lowercut, uppercut)
 return np.mean(atmp[sl], axis=axis)

def trim_mean ( a , proportiontocut , axis = 0 ) : a = np . asarray ( a ) if ( a . size == 0 ) : return np . nan if ( axis is None ) : a = a . ravel ( ) axis = 0 nobs = a . shape [ axis ] lowercut = int ( ( proportiontocut * nobs ) ) uppercut = ( nobs - lowercut ) if ( lowercut > uppercut ) : raise ValueError ( 'Proportion too big.' ) atmp = np . partition ( a , ( lowercut , ( uppercut - 1 ) ) , axis ) sl = ( [ slice ( None ) ] * atmp . ndim ) sl [ axis ] = slice ( lowercut , uppercut ) return np . mean ( atmp [ sl ] , axis = axis )
return mean of array after trimming distribution from both tails .