Skip to content

Instantly share code, notes, and snippets.

@kwcooper
Created January 16, 2020 03:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kwcooper/9e71076c6532c1432fd4f103f3323058 to your computer and use it in GitHub Desktop.
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.
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))
@kwcooper
Copy link
Author

tbh could probably do without the variables in line 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment