Created
January 16, 2020 03:12
-
-
Save kwcooper/9e71076c6532c1432fd4f103f3323058 to your computer and use it in GitHub Desktop.
Ftn that takes a list of numbers and scales it within the bounds of the given arguments.
This file contains 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
def scaleInRange(lon, a, b): | |
r_max, r_min = max(lon), min(lon) | |
slon = [] | |
for i in lon: | |
slon.append(((i - r_min) / (r_max - r_min)) * (b - a) + a) | |
return slon | |
# Example | |
lon = range(1,100) | |
a, b, = 4, 8 | |
print(scaleInRange(lon, a, b)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tbh could probably do without the variables in line 2