def bytescale(data, cmin=None, cmax=None, high=255, low=0):
 if (data.dtype == uint8):
  return data
 if (high > 255):
  raise ValueError('`high` should be less than or equal to 255.')
 if (low < 0):
  raise ValueError('`low` should be greater than or equal to 0.')
 if (high < low):
  raise ValueError('`high` should be greater than or equal to `low`.')
 if (cmin is None):
  cmin = data.min()
 if (cmax is None):
  cmax = data.max()
 cscale = (cmax - cmin)
 if (cscale < 0):
  raise ValueError('`cmax` should be larger than `cmin`.')
 elif (cscale == 0):
  cscale = 1
 scale = (float((high - low)) / cscale)
 bytedata = (((data - cmin) * scale) + low)
 return (bytedata.clip(low, high) + 0.5).astype(uint8)

def bytescale ( data , cmin = None , cmax = None , high = 255 , low = 0 ) : if ( data . dtype == uint8 ) : return data if ( high > 255 ) : raise ValueError ( '`high` should be less than or equal to 255.' ) if ( low < 0 ) : raise ValueError ( '`low` should be greater than or equal to 0.' ) if ( high < low ) : raise ValueError ( '`high` should be greater than or equal to `low`.' ) if ( cmin is None ) : cmin = data . min ( ) if ( cmax is None ) : cmax = data . max ( ) cscale = ( cmax - cmin ) if ( cscale < 0 ) : raise ValueError ( '`cmax` should be larger than `cmin`.' ) elif ( cscale == 0 ) : cscale = 1 scale = ( float ( ( high - low ) ) / cscale ) bytedata = ( ( ( data - cmin ) * scale ) + low ) return ( bytedata . clip ( low , high ) + 0.5 ) . astype ( uint8 )
byte scales an array .