K-d tree: Difference between revisions

Line 1,301:
 
See also: [[wp:KISS_principle]]
 
 
=={{header|Julia}}==
<lang julia>using NearestNeighbors
 
const data = [[2, 3] [5, 4] [9, 6] [4, 7] [8, 1] [7, 2]]
 
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).\n")
 
const cubedis = rand(3, 1000)
const kdcubetree = KDTree(cubedis)
const rand3point = rand(3, 1)
idxs, dists = knn(kdcubetree, rand3point, 1)
 
println("The point $rand3point is closest to the point $(cubedis[1:3, idxs[1]])",
" at distance ($dists[1]).")
</lang>
{{out}}
<pre>
Wikipedia example: The nearest neighbor to [9, 2] is [8, 1] at distance [1.41421].
The point [0.639401; 0.576214; 0.587777] is closest to the point [0.661115; 0.533108; 0.615634] at distance
(Array{Float64,1}[[0.055728]][1]).
</pre>
 
=={{header|Kotlin}}==
4,107

edits