比例转换

def rescale(value, curr_min, curr_max, new_min, new_max):
    """Convert the value from one scale to a new scale.
    
    Args:
        value (int/float/object): Value to convert to the new scale
        curr_max (int/float): Current maximum value for the current scale.
        curr_min (int/float): Current minimum value for the current scale.
        new_max (int/float): New maximum value for the new scale.
        new_min (int/float): New minimum value for the new scale.
        
    Returns:
        value (int/float/object): New value that was converted to the new scale
    """
    return ((value - curr_min) / (curr_max - curr_min)) * (new_max - new_min) + new_min
posted @ 2021-03-15 13:46  lisicn  阅读(236)  评论(0)    收藏  举报