Created
October 16, 2022 15:31
-
-
Save galenseilis/1689ed908f7bca0dea9a52c5eda1bff7 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
| import numpy as np | |
| def scale(x, a=0, b=1): | |
| if a > b: | |
| a, b = b, a | |
| min_x = np.min(x) | |
| result = (x - min_x) / (np.max(x) - min_x) | |
| result *= (b - a) | |
| result += a | |
| return result | |
| if __name__ == '__main__': | |
| x = np.array([1, 3, 4, 5, -1, -7]) | |
| print(scale(x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment