indmax

indmax(itr) -> Integer

Returns the index of the maximum element in a collection.

Examples

  1. Find the index of the maximum element in an array:

    julia> arr = [5, 10, 3, 8, 2];
    julia> indmax(arr)
    2

    This example returns the index of the maximum element in the array arr.

  2. Find the index of the maximum element in a vector of strings:

    julia> words = ["apple", "banana", "orange", "grape"];
    julia> indmax(words)
    3

    It returns the index of the maximum element in the vector of strings.

  3. Handle edge cases when the maximum element is at the beginning or end:
    julia> numbers = [10, 5, 3, 7, 10];
    julia> indmax(numbers)
    1

    It correctly handles the case where the maximum element is at the beginning of the collection.

Common mistake example:

julia> arr = [];
julia> indmax(arr)
ERROR: MethodError: no method matching indmax(::Array{Any,1})

In this example, an empty array is passed to indmax. The function expects a non-empty collection, so it throws an error. Make sure to pass a valid collection to indmax 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: