Skip to content

Instantly share code, notes, and snippets.

@CMCDragonkai
Last active May 4, 2021 07:53
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CMCDragonkai/6444bf7ea41b4f43766abb9f4294cd69 to your computer and use it in GitHub Desktop.
Save CMCDragonkai/6444bf7ea41b4f43766abb9f4294cd69 to your computer and use it in GitHub Desktop.
Numpy Scale Range (a.k.a. Normalisation) #python #numpy
import numpy as np
# scale an input array-like to a mininum and maximum number
# the input array must be of a floating point array
# if you have a non-floating point array, convert to floating using `astype('float')`
# this works with n-dimensional arrays
# it will mutate in place
# min and max can be integers
def scale_range (input, min, max):
input += -(np.min(input))
input /= np.max(input) / (max - min)
input += min
return input
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment