在 Julia 中检查数组中的真值 - any() 和 all() 方法
any()
是 julia 中的一个内置函数,用于测试指定布尔集合的任何元素是否为真,如果任何输入值“缺失”,如果所有非缺失值都为假,它将返回缺失。
Syntax: any(itr)
Parameters:
- itr: Specified boolean collection.
Returns: It returns true if any of the value of specified boolean collection is true. And also return missing value if all non-missing values are false in the boolean collection.
示例 1:
# Julia program to illustrate
# the use of any() method
# Getting true if any of the value
# of specified boolean collection is
# true. And also return missing value
# if all non-missing values are false
# in the boolean collection.
println(any([true, false, true, false]))
println(any([true, true, true, true]))
println(any([false, false, false, false]))
println(any([missing, true, true]))
println(any([false, missing, true]))
println(any([false, missing, false]))
输出:
全部()
all()是 julia 中的一个内置函数,用于测试指定布尔集合的任何元素是否为真,如果任何输入值“缺失”,如果所有非缺失值都为真,它将返回缺失。Syntax:
all(itr)
Parameters:
- itr: Specified boolean collection.
Returns: It returns false if any of the value of specified boolean collection is false. And also return missing value if all non-missing values are true in the boolean collection.
示例 1:
# Julia program to illustrate
# the use of all() method
# Getting false if any of the value
# of specified boolean collection is
# false. And also return missing value
# if all non-missing values are true
# in the boolean collection.
println(all([true, false, true, false]))
println(all([true, true, true, true]))
println(all([false, false, false, false]))
println(all([missing, true, true]))
println(all([false, missing, true]))
println(all([false, missing, false]))
输出: