Skip to content

Instantly share code, notes, and snippets.

@mattwthompson
Created January 30, 2018 18:58
Show Gist options
  • Save mattwthompson/3071329482f2bd0cf958d60bc96e7186 to your computer and use it in GitHub Desktop.
Save mattwthompson/3071329482f2bd0cf958d60bc96e7186 to your computer and use it in GitHub Desktop.
import numpy as np
def find_nearest(distances, val):
idx = (np.abs(distances[:, 1] - val)).argmin()
return distances[idx, 0]
spacing = 0.05
distances = np.loadtxt('distance_summary.dat')
min_val = np.floor(np.min(distances[:, 1]) / spacing) * spacing
max_val = np.ceil(np.max(distances[:, 1]) / spacing) * spacing
num_val = 1 + int((max_val - min_val) / spacing)
print('conf #\tCOM distance')
for val in np.linspace(min_val, max_val, num_val):
idx = find_nearest(distances, val)
print(int(idx), '\t', round(val, 3))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment