在 Julia 中获取最小元素 – minimum() 和 minimum!() 方法
minimum()是 julia 中的内置函数,用于返回不同场景中的最小元素。
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.
例子:
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", "Geeks", "GeeksforGeeks"]))
# 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))
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))
输出:
最低限度!()
minimum!()是 julia 中的内置函数,用于计算指定数组在指定单例维度上的最小值。
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.
例子:
朱莉娅
# 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))
输出:
[5, 15]
[5 10]