Created
July 25, 2019 17:16
-
-
Save ninjakx/a2c5beedfe02d8e6761cce83e61e2afe 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
%%time | |
a = nearest_ngbr_raw(arr) |
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
print(open('sim_result', 'r').read()) |
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
%%writefile simulation.py | |
import numpy as np | |
def comp_inner_raw(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_raw(x): | |
dist = {} | |
for idx,i in enumerate(x): | |
lst = comp_inner_raw(i,x) | |
s = np.argsort(lst) | |
sorted_array = np.array(x)[s][1:] | |
dist[idx] = s[1:] | |
return dist |
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 numpy as np | |
%load_ext line_profiler |
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
arr = np.random.rand(1000,800) |
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
from simulation import nearest_ngbr_raw | |
%lprun -T sim_result -f nearest_ngbr_raw nearest_ngbr_raw(arr) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment