Getting minimum elements in Julia – minimum() and minimum!() Methods
The minimum() is an inbuilt function in julia which is used to return minimum elements in different scenario.
Syntax:
minimum(f, itr)
or
minimum(itr)
or
minimum(A::AbstractArray; dims)Parameters:
- f: Specified function.
- itr: Specified list of elements.
- A::AbstractArray: Specified array of different dimensions.
- dims: Specified dimensions.
Returns: It returns the minimum elements in different scenario.
Example:
Julia
# Julia program to illustrate # the use of minimum() method # Getting minimum elements in different scenarios # In the below scenario, length function # and a list of elements are used as # parameter. Here the length of string with # minimum alphabets will be returned println(minimum(length, [ "GFG" , "Beginner" , "w3wiki" ])) # In the below scenario, a list of # elements are shown and minimum elements are # returned as output println(minimum([ 5 , 10 , 15 , 20 ])) # Getting the minimum value of an array # over the given dimensions A = [ 5 10 ; 15 20 ]; println(minimum(A, dims = 1 )) println(minimum(A, dims = 2 )) |
Output:
minimum!()
The minimum!() is an inbuilt function in julia which is used to calculate the minimum value of the specified array over the specified singleton dimensions.
Syntax: minimum!(r, A)
Parameters:
- r: Specified singleton dimensions.
- A: Specified array.
Returns: It returns the minimum value of the specified array over the specified singleton dimensions.
Example:
Julia
# Julia program to illustrate # the use of minimum !() method # Getting the minimum value of the # specified array over the specified # singleton dimensions. A = [ 5 10 ; 15 20 ]; println(minimum !([ 1 ; 1 ], A)) println(minimum !([ 1 1 ], A)) |
Output:
[5, 15] [5 10]
Contact Us