📜  在 Julia 中获取最小元素及其索引 – findmin() 方法

📅  最后修改于: 2022-05-13 01:55:46.310000             🧑  作者: Mango

在 Julia 中获取最小元素及其索引 – findmin() 方法

findmin()是 julia 中的一个内置函数,用于返回指定集合的最小元素及其索引。如果集合中存在多个最小元素,则将返回第一个。如果有任何数据元素为 NaN,则返回该元素。

示例 1:

Julia
# Julia program to illustrate
# the use of findmin() method
 
# Getting the minimum 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]))


Julia
# 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))


输出:

示例 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))

输出: