Last active
October 5, 2016 07:38
-
-
Save endlesspint8/3a5d1b960d52bc14318dcafe1da6811d to your computer and use it in GitHub Desktop.
miscellany to, http://endlesspint.com/
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
# http://stackoverflow.com/questions/929103/convert-a-number-range-to-another-range-maintaining-ratio | |
def new_value(orig_inputs, new_min, new_max, old_value): | |
old_min = min(orig_inputs) | |
old_max = max(orig_inputs) | |
old_range = old_max - old_min | |
new_range = new_max - new_min | |
new_value = ((old_value - old_min) * new_range / old_range) + new_min | |
return new_value | |
import numpy as np | |
rand_input = np.random.random_integers(5, 2500, 10) | |
print rand_input | |
# [1512 1487 764 594 1176 1593 2062 1996 1279 56] | |
for i in rand_input: | |
print i, new_value(rand_input, 0., 1., i) | |
# 1512 0.725822532403 | |
# 1487 0.713359920239 | |
# 764 0.352941176471 | |
# 594 0.268195413759 | |
# 1176 0.558325024925 | |
# 1593 0.766201395813 | |
# 2062 1.0 | |
# 1996 0.967098703888 | |
# 1279 0.609670987039 | |
# 56 0.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment