findmin(A,dims)
findmin(A, dims) -> (minval, index)
For an array input, returns the value and index of the minimum over the given dimensions.
Examples
-
Find the minimum element and index in an array:
julia> arr = [8, 2, 5, 1, 9]; julia> findmin(arr) (1, 4)This example finds the minimum element in the array
arrand returns the value1along with its index4. -
Find the minimum element and index in a range:
julia> rng = 1:10; julia> findmin(rng) (1, 1)It finds the minimum element in the range
1:10and returns the value1along with its index1. - Find the minimum element and index in a tuple:
julia> tpl = (5, 2, 8, 3); julia> findmin(tpl) (2, 2)The function can also be used to find the minimum element and its index in a tuple.
Common mistake example:
julia> findmin([])
ERROR: MethodError: no method matching findmin(::Array{Int64,1})
In this example, an empty array is passed to the findmin function. It results in a MethodError since it expects a non-empty iterable as an argument. Ensure that the input collection is not empty when using findmin.
See Also
find, findfirst, findin, findlast, findmin, findn, findnext, findnz, findprev, rsearch, rsearchindex, searchsorted, searchsortedfirst, searchsortedlast, sort, sort!, sortcols, sortperm, sortperm!,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.