November 2018
Intermediate to advanced
460 pages
14h 1m
English
In this recipe, we compare two functions that find all indices of minimal elements in an array. One is simple, but slower; the other is more elaborate, but faster. We compare their outputs and execution speeds:
julia> function allargmin(a) m = minimum(a) filter(i -> a[i] == m, eachindex(a)) endallargmin (generic function with 1 method)
julia> allargmin([1,2,3,1,2,3])2-element Array{Int64,1}: 1 4
The result is correct.
julia> randargmin1(a) = rand(allargmin(a)) ...
Read now
Unlock full access