findmin()
是 julia 中的一个内置函数,用于返回指定集合的最小元素及其索引。如果集合中存在多个最小元素,则将返回第一个。如果有任何数据元素是 NaN,则返回此元素。
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.
示例 1:
# 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]))
输出:
示例 2:
# 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))
输出: