Find maximum element along with its index in Julia – findmax() Method

The findmax() is an inbuilt function in julia which is used to return the maximum element of the specified collection along with its index. If there are multiple maximal elements are present in the collection, then the first one will be returned. If there is any data element is NaN, this element is returned.

Syntax:
findmax(itr)
or
findmax(A; dims)

Parameters:

  • itr: Specified collection of elements.
  • A: Specified array.
  • dims: Specified dimension.

Returns: It returns the maximum elements with their corresponding index.

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

# Julia program to illustrate 
# the use of findmax() method
  
# Getting the maximum elements
# with their corresponding index.
println(findmax([1, 2, 3, 4]))
println(findmax([5, 0, false, 6]))
println(findmax([1, 2, 3, true]))
println(findmax([5, 0, NaN, 6]))
println(findmax([1, 2, 3, 3]))

chevron_right


Output:

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# Julia program to illustrate 
# the use of findmax() method
  
# Getting the value and index of
# the maximum over the given dimensions
A = [5 10; 15 20];
println(findmax(A, dims = 1))
println(findmax(A, dims = 2))

chevron_right


Output:

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.