Last active
September 26, 2015 11:20
-
-
Save adidonato/5c19e53749d2f220a529 to your computer and use it in GitHub Desktop.
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
#!/usr/local/bin/blue-python2.7 | |
""" | |
TESTED WITH: | |
array = np.random.random(10) | |
value = 0.5 | |
WHICH RESULTED IN: | |
value = 0.5 | |
array = [ 0.6205113 0.85115237 0.47712603 0.12206011 0.59412783 0.57985636 0.0870805 0.39377825 0.12342532 0.51721711] | |
bucket = 0.517217107966 | |
""" | |
import sys | |
import numpy as np | |
def find_nearest(array,value): | |
idx = (np.abs(array-value)).argmin() | |
return array[idx] | |
for line in sys.stdin.readlines(): | |
line = line.strip() | |
array = line[0] | |
value = line[1] | |
bucket = find_nearest(array, value) | |
print ("%s\t%s\t%s\n" % (value, array, bucket)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment