Skip to content

Instantly share code, notes, and snippets.

@ninjakx
Last active July 26, 2019 07:31
Show Gist options
  • Save ninjakx/85ed714ba4c3aafac7a5a2b3466b8f25 to your computer and use it in GitHub Desktop.
Save ninjakx/85ed714ba4c3aafac7a5a2b3466b8f25 to your computer and use it in GitHub Desktop.
from numba import jit, njit
@jit('float64[:](float64[:], float64[:, :])')
def comp_inner_numba(i, x):
res = np.zeros(x.shape[0], dtype=np.float64)
for j in range(x.shape[0]):
res[j] = np.sqrt(np.sum((i-x[j])**2))
return res
def nearest_ngbr_numba(x):
dist = {}
for idx,i in enumerate(x):
lst = comp_inner_numba(i,x)
s = np.argsort(lst)
sorted_array = np.array(x)[s][1:]
dist[idx] = s[1:]
return dist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment