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:

  1. 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 index 2 in the array arr.

  2. 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 index 3 in the vector of strings.

  3. 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 index 10 in the range 1: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.

*Required Field
Details

Checking you are not a robot: