Created
February 14, 2021 10:04
-
-
Save ahue/f7beb83c154451fe21517a34e41e3bb6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from typing import Union | |
| def scale(x: Union[int|float], | |
| min_x: Union[int|float], max_x: Union[int|float], | |
| a: Union[int|float], b: Union[int|float]) -> float: | |
| """ | |
| Scale a number x relative to domain [min_x, max_x] to a domain [a,b] | |
| Parameters: | |
| x (int|float): The value to scale | |
| min_x (int|float): Lower bound of the domain x is coming from | |
| max_x (int|float): Upper bound of the domain x is coming from | |
| a (int|float): Lower bound of the target domain | |
| b (int|float): Upper bound of the target domain | |
| Returns: | |
| scaled_x (float): The scaled value of x | |
| """ | |
| return (b-a) * (x-min_x) / (max_x-min_x) + a |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment