def trima(a, limits=None, inclusive=(True, True)):
 a = ma.asarray(a)
 a.unshare_mask()
 if ((limits is None) or (limits == (None, None))):
  return a
 (lower_lim, upper_lim) = limits
 (lower_in, upper_in) = inclusive
 condition = False
 if (lower_lim is not None):
  if lower_in:
   condition |= (a < lower_lim)
  else:
   condition |= (a <= lower_lim)
 if (upper_lim is not None):
  if upper_in:
   condition |= (a > upper_lim)
  else:
   condition |= (a >= upper_lim)
 a[condition.filled(True)] = masked
 return a

def trima ( a , limits = None , inclusive = ( True , True ) ) : a = ma . asarray ( a ) a . unshare_mask ( ) if ( ( limits is None ) or ( limits == ( None , None ) ) ) : return a ( lower_lim , upper_lim ) = limits ( lower_in , upper_in ) = inclusive condition = False if ( lower_lim is not None ) : if lower_in : condition |= ( a < lower_lim ) else : condition |= ( a <= lower_lim ) if ( upper_lim is not None ) : if upper_in : condition |= ( a > upper_lim ) else : condition |= ( a >= upper_lim ) a [ condition . filled ( True ) ] = masked return a
trims an array by masking the data outside some given limits .