Jaccard index: Difference between revisions

julia example
No edit summary
(julia example)
Line 53:
{ 8 } { 8 } -> 1
</pre>
 
=={{header|Julia}}==
<lang julia>J(A, B) = begin i, u = length(A ∩ B), length(A ∪ B); u == 0 ? NaN : i // u end
 
A = Int[]
B = [1, 2, 3, 4, 5]
C = [1, 3, 5, 7, 9]
D = [2, 4, 6, 8, 10]
E = [2, 3, 5, 7]
F = [8]
testsets = [A, B, C, D, E, F]
 
println("Set A Set B J(A, B)\n", "-"^44)
for a in testsets, b in testsets
println(rpad(isempty(a) ? "[]" : a, 18), rpad(isempty(b) ? "[]" : b, 18),
replace(string(J(a, b)), "//" => "/"))
end
</lang>{{out}}
<pre>
Set A Set B J(A, B)
--------------------------------------------
[] [] NaN
[] [1, 2, 3, 4, 5] 0/1
[] [1, 3, 5, 7, 9] 0/1
[] [2, 4, 6, 8, 10] 0/1
[] [2, 3, 5, 7] 0/1
[] [8] 0/1
[1, 2, 3, 4, 5] [] 0/1
[1, 2, 3, 4, 5] [1, 2, 3, 4, 5] 1/1
[1, 2, 3, 4, 5] [1, 3, 5, 7, 9] 3/7
[1, 2, 3, 4, 5] [2, 4, 6, 8, 10] 1/4
[1, 2, 3, 4, 5] [2, 3, 5, 7] 1/2
[1, 2, 3, 4, 5] [8] 0/1
[1, 3, 5, 7, 9] [] 0/1
[1, 3, 5, 7, 9] [1, 2, 3, 4, 5] 3/7
[1, 3, 5, 7, 9] [1, 3, 5, 7, 9] 1/1
[1, 3, 5, 7, 9] [2, 4, 6, 8, 10] 0/1
[1, 3, 5, 7, 9] [2, 3, 5, 7] 1/2
[1, 3, 5, 7, 9] [8] 0/1
[2, 4, 6, 8, 10] [] 0/1
[2, 4, 6, 8, 10] [1, 2, 3, 4, 5] 1/4
[2, 4, 6, 8, 10] [1, 3, 5, 7, 9] 0/1
[2, 4, 6, 8, 10] [2, 4, 6, 8, 10] 1/1
[2, 4, 6, 8, 10] [2, 3, 5, 7] 1/8
[2, 4, 6, 8, 10] [8] 1/5
[2, 3, 5, 7] [] 0/1
[2, 3, 5, 7] [1, 2, 3, 4, 5] 1/2
[2, 3, 5, 7] [1, 3, 5, 7, 9] 1/2
[2, 3, 5, 7] [2, 4, 6, 8, 10] 1/8
[2, 3, 5, 7] [2, 3, 5, 7] 1/1
[2, 3, 5, 7] [8] 0/1
[8] [] 0/1
[8] [1, 2, 3, 4, 5] 0/1
[8] [1, 3, 5, 7, 9] 0/1
[8] [2, 4, 6, 8, 10] 1/5
[8] [2, 3, 5, 7] 0/1
[8] [8] 1/1
</pre>
 
 
=={{header|Wren}}==
4,103

edits