Skip to content
Related Articles

Related Articles

Getting minimum element along with its index in Julia – findmin() Method
  • Last Updated : 26 Mar, 2020

The findmin() is an inbuilt function in julia which is used to return the minimum element of the specified collection along with its index. If there are multiple minimal 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:
findmin(itr)
or
findmin(A; dims)

Parameters:

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

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

Example 1:



filter_none

edit
close

play_arrow

link
brightness_4
code

# Julia program to illustrate 
# the use of findmin() method
  
# Getting the mimimum elements
# with their corresponding index.
println(findmin([1, 2, 3, 4]))
println(findmin([5, 0, false, 6]))
println(findmin([1, 2, 3, true]))
println(findmin([5, 0, NaN, 6]))
println(findmin([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 findmin() method
  
# Getting the value and index of
# the minimum over the given dimensions
A = [5 10; 15 20];
println(findmin(A, dims = 1))
println(findmin(A, dims = 2))

chevron_right


Output:

My Personal Notes arrow_drop_up
Recommended Articles
Page :