Created
October 22, 2019 09:50
-
-
Save wolframalpha/12fc23cc753acb8913fbcd739bef7ffa 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
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