findmax(A,dims)
findmax(A, dims) -> (maxval, index)
For an array input, returns the value and index of the maximum over the given dimensions.
Examples
In the Julia programming language, the function findmax(itr)
Returns the maximum element and its index from the iterable itr
.
julia> findmax([5, 10, 3, 8, 2])
(10, 2)
Provide common examples of its use:
-
Find the maximum element and its index in an array:
julia> arr = [5, 10, 3, 8, 2]; julia> findmax(arr) (10, 2)
This example returns the maximum element
10
and its index2
in the arrayarr
. -
Find the maximum element and its index in a vector of strings:
julia> words = ["apple", "banana", "orange", "grape"]; julia> findmax(words) ("orange", 3)
It returns the maximum element
"orange"
and its index3
in the vector of strings. - Find the maximum element and its index in a range:
julia> r = 1:10; julia> findmax(r) (10, 10)
It finds the maximum element
10
and its index10
in the range1:10
.
Common mistake example:
julia> findmax([])
ERROR: MethodError: no method matching findmax(::Array{Int64,1})
In this example, an empty array is passed to findmax
, causing a MethodError
. Make sure to provide a non-empty iterable to findmax
to avoid such errors.
See Also
cummax, eigmax, findmax, hist, hist!, hist2d, hist2d!, histrange, indmax, maxabs, maxabs!, maximum!, mean, mean!, median, median!, minabs, minabs!, minimum!, minmax, quantile!, realmax, std, stdm,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.