Skip to content

Instantly share code, notes, and snippets.

@wolframalpha
Created October 22, 2019 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wolframalpha/12fc23cc753acb8913fbcd739bef7ffa to your computer and use it in GitHub Desktop.
Save wolframalpha/12fc23cc753acb8913fbcd739bef7ffa to your computer and use it in GitHub Desktop.
import pandas as pd
import numpy as np
def closest_node(node, nodes):
nodes = np.asarray(nodes)
dist_2 = np.sum((nodes - node)**2, axis=1)
return np.argmin(dist_2)
shelf_1 = [(2,1), (1,2)]
shelf_2 = [(2,3), (3,4)]
nodes = shelf_1 + shelf_2
nodes
idx = closest_node((5,3), nodes)
closest_node = nodes[idx]
closest_node in shelf_2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment