def rescale_arr(arr, amin, amax):

    # old bounds
    m = arr.min()
    M = arr.max()
    # scale/offset
    s = float(amax - amin) / (M - m)
    d = amin - s * m

    # Apply clip before returning to cut off possible overflows outside the
    # intended range due to roundoff error, so that we can absolutely guarantee
    # that on output, there are no values > amax or < amin.
    return np.clip(s * arr + d, amin, amax)
Rescale an array to a new range.
dataset/ETHPy150Open nipy/nitime/nitime/utils.py/rescale_arr