Rescale values to fit a certain range [min, max]
972399
def rescale(x, min=0., max=1., axis=0):
    
    def innerfn(x, min, max):
        return np.interp(x, [np.min(x), np.max(x)], [min, max])

    if isinstance(x, pd.DataFrame):
        return x.apply(innerfn, axis=axis, args=(min, max,))
    else:
        return pd.Series(innerfn(x, min, max), index=x.index)
679417
def _get_min_max_value(min, max, value=None, step=None):
    """"""
    # Either min and max need to be given, or value needs to be given
    if value is None:
        if min is None or max is None:
            raise ValueError('unable to infer range, value from: ({0}, {1}, {2})'.format(min, max, value))
        diff = max - min
        value = min + (diff / 2)
        # Ensure that value has the same type as diff
        if not isinstance(value, type(diff)):
            value = min + (diff // 2)
    else:  # value is not None
        if not isinstance(value, Real):
            raise TypeError('expected a real number, got: %r' % value)
        # Infer min/max from value
        if value == 0:
            # This gives (0, 1) of the correct type
            vrange = (value, value + 1)
        elif value > 0:
            vrange = (-value, 3*value)
        else:
            vrange = (3*value, -value)
        if min is None:
            min = vrange[0]
        if max is None:
            max = vrange[1]
    if step is not None:
        # ensure value is on a step
        tick = int((value - min) / step)
        value = min + tick * step
    if not min <= value <= max:
        raise ValueError('value must be between min and max (min={0}, value={1}, max={2})'.format(min, value, max))
    return min, max, value
1172061
def set_range(self, bounds, keep_aspect=False):
        """"""
        # a * (v0 + t) = -1
        # a * (v1 + t) = +1
        # =>
        # a * (v1 - v0) = 2
        bounds = np.asarray(bounds, dtype=np.float64)
        v0 = bounds[:2]
        v1 = bounds[2:]
        pan = -.5 * (v0 + v1)
        zoom = 2. / (v1 - v0)
        if keep_aspect:
            zoom = zoom.min() * np.ones(2)
        self.set_pan_zoom(pan=pan, zoom=zoom)
471463
def _normalize(arr, keep_ratio=False):
    """"""
    (x_min, y_min), (x_max, y_max) = arr.min(axis=0), arr.max(axis=0)

    if keep_ratio:
        a = 1. / max(x_max - x_min, y_max - y_min)
        ax = ay = a
        bx = .5 - .5 * a * (x_max + x_min)
        by = .5 - .5 * a * (y_max + y_min)
    else:
        ax = 1. / (x_max - x_min)
        ay = 1. / (y_max - y_min)
        bx = -x_min / (x_max - x_min)
        by = -y_min / (y_max - y_min)

    arr_n = arr.copy()
    arr_n[:, 0] *= ax
    arr_n[:, 0] += bx
    arr_n[:, 1] *= ay
    arr_n[:, 1] += by

    return arr_n
556416
def min_ems(self, value: float) -> 'Size':
        """"""
        raise_not_number(value)
        self.minimum = '{}em'.format(value)
        return self
746529
function inRange (data, x, y) {
    if (x < y) {
      return greaterOrEqual(data, x) && data <= y;
    }

    return lessOrEqual(data, x) && data >= y;
  }
432150
def _argparse_minmax_type(self, string):
        """"""
        value = float(string)
        if value < 0 or value > 8:
            raise argparse.ArgumentTypeError(
                '%s must be between 0.0 and 8.0' % string,
            )

        return value
87450
function adjustRange(w, bisect) {
  var r0 = w.i0,
      r1 = w.i1 - 1,
      c = w.compare,
      d = w.data,
      n = d.length - 1;

  if (r0 > 0 && !c(d[r0], d[r0-1])) w.i0 = bisect.left(d, d[r0]);
  if (r1 < n && !c(d[r1], d[r1+1])) w.i1 = bisect.right(d, d[r1]);
}
1156507
def scale(input_value, input_min, input_max, out_min, out_max):
    
    # Figure out how 'wide' each range is
    input_span = input_max - input_min
    output_span = out_max - out_min
    # Convert the left range into a 0-1 range (float)
    valuescaled = float(input_value - input_min) / float(input_span)
    # Convert the 0-1 range into a value in the right range.
    return out_min + (valuescaled * output_span)
913112
function MinMaxScalerTransforms(vector = [], nan_value = -1, return_nan=false) {
              const average = avg$2(vector);
              const standard_dev = sd(vector);
              const maximum = max$1(vector);
              const minimum = min$1(vector);
              const scale = (z) => {
                const scaledValue = (z - average) / (maximum - minimum);
                if (isNaN(scaledValue) && return_nan) return scaledValue;
                else if (isNaN(scaledValue) && return_nan === false) return (isNaN(standard_dev)) ? z : standard_dev;
                else return scaledValue;
              }; // equivalent to MinMaxScaler(z)
              const descale = (scaledZ) => {
                const descaledValue = (scaledZ * (maximum - minimum)) + average;
                if (isNaN(descaledValue) && return_nan) return descaledValue;
                else if (isNaN(descaledValue) && return_nan === false) return (isNaN(standard_dev)) ? scaledZ : standard_dev;
                else return descaledValue;
              };
              const values = vector.map(scale)
                .map(val => {
                  if (isNaN(val)) return nan_value;
                  else return val;
                });
              return {
                components: {
                  average,
                  standard_dev,
                  maximum,
                  minimum,
                },
                scale,
                descale,
                values,
              };
            }
267470
private Double scale(Double value, Double min, Double max) {
        if(min.equals(max)) {
            if(value>max) {
                return 1.0;
            }
            else if(value==max && value!=0.0) {
                return 1.0;
            }
            else {
                return 0.0;
            }
        }
        else {
            return (value-min)/(max-min);
        }
    }
432916
def clamp(n, lower, upper):
    
    if lower > upper:
        lower, upper = upper, lower
    return max(min(upper, n), lower)
1283317
def _rescale_array(self, array, scale, zero):
        
        if scale != 1.0:
            sval = numpy.array(scale, dtype=array.dtype)
            array *= sval
        if zero != 0.0:
            zval = numpy.array(zero, dtype=array.dtype)
            array += zval
988331
def rescale(curves, values):
    
    A, _, C = curves.shape
    assert A == len(values), (A, len(values))
    array = numpy.zeros((A, C), loss_poe_dt)
    array['loss'] = [c * v for c, v in zip(curves[:, 0], values)]
    array['poe'] = curves[:, 1]
    return array
435303
def scale_to(x, ratio, targ): 
    ''''''
    return max(math.floor(x*ratio), targ)
910623
def PARAMLIMITS(self, value):
        """"""
        assert set(value.keys()) == set(self.PARAMLIMITS.keys()), "The \
                new parameter limits are not defined for the same set \
                of parameters as before."
        for param in value.keys():
            assert value[param][0] < value[param][1], "The new \
                    minimum value for {0}, {1}, is equal to or \
                    larger than the new maximum value, {2}"\
                    .format(param, value[param][0], value[param][1])
        self._PARAMLIMITS = value.copy()
771248
def repval(self, limitsok=False):
        """"""

        if not limitsok and self.dkind in ('lower', 'upper'):
            raise LimitError()

        if self.dkind == 'unif':
            lower, upper = map(float, self.data)
            v = 0.5 * (lower + upper)
        elif self.dkind in _noextra_dkinds:
            v = float(self.data)
        elif self.dkind in _yesextra_dkinds:
            v = float(self.data[0])
        else:
            raise RuntimeError('can\'t happen')

        if self.tkind == 'log10':
            return 10**v
        return v