Last active
May 4, 2021 07:53
-
-
Save CMCDragonkai/6444bf7ea41b4f43766abb9f4294cd69 to your computer and use it in GitHub Desktop.
Numpy Scale Range (a.k.a. Normalisation) #python #numpy
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
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