K-d tree: Difference between revisions
m
→{{header|Julia}}
Line 1,304:
=={{header|Julia}}==
<lang julia>
using NearestNeighbors
const data = [[2, 3] [5, 4] [9, 6] [4, 7] [8, 1] [7, 2]]
NearestNeighbors.reset_stats()
const kdtree = KDTree(Float64.(data))
const indexpoint = [9,2]
idxs, dists = knn(kdtree, indexpoint, 1)
println("Wikipedia example: The nearest neighbor to $indexpoint is ",
"$(data[1:2, idxs[1]]) at distance $(dists).
NearestNeighbors.print_stats()
NearestNeighbors.reset_stats()
const cubedis = rand(3, 1000)
const kdcubetree = KDTree(cubedis)
Line 1,319 ⟶ 1,324:
idxs, dists = knn(kdcubetree, rand3point, 1)
println("
" at distance $(dists[1]).")
NearestNeighbors.print_stats()
</lang>
{{out}}
Wikipedia example: The nearest neighbor to [9, 2] is [8, 1] at distance [1.41421].
Nodes visited: 1
Points visited: 6, out of these: 0 unchecked.
The point [0.
Nodes visited: 7
</pre>
|