Search code examples
juliaminimum

How to find value and index of the minimum value of an array in Julia?


I have a 5-element array,

5-element Array{Any,1}:
 0.7720227280667112
 0.2220636729556234
 0.2917295078541099
 0.0673233060720263
 0.11171893016863099

I want to get the minimum value (0.06) and its index! How can I do it?


Solution

  • You can use the [findmin]1 function like this:

     julia> a = [0.7720227280667112; 0.2220636729556234; 0.2917295078541099; 0.0673233060720263; 0.11171893016863099]
    5-element Vector{Float64}:
     0.7720227280667112
     0.2220636729556234
     0.2917295078541099
     0.0673233060720263
     0.11171893016863099
    
    julia> findmin(a)
    (0.0673233060720263, 4)