📌  相关文章
📜  检查数组的特定索引是否包含 Julia 中的值 - isassigned() 方法

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

检查数组的特定索引是否包含 Julia 中的值 - isassigned() 方法

isassigned()是 julia 中的内置函数,用于测试给定索引是否包含指定数组中的值。

示例 1:

# Julia program to illustrate 
# the use of Array isassigned() method
   
# test whether the given index value 3 is
# present in the 1D array A.
A = [5, 10, 15, 20]
println(isassigned(A, 3))
   
# test whether the given index value 5 is
# present in the 2D array B of size 2 * 2
B = [5 10; 15 20]
println(isassigned(B, 5))
   
# test whether the given index value 9 is
# present in the 3D array C of size 2 * 2*2
C = cat([1 2; 3 4], [5 6; 7 8], 
        [9 10; 11 12], dims = 3)
println(isassigned(C, 9))

输出:
示例 2:

# Julia program to illustrate 
# the use of Array isassigned() method
    
# test whether the given index value 3 is
# present in the 1D array A.
A = [1, 2, 3];
println(isassigned(A, 10))
    
# test whether the given index value 5 is
# present in the 2D array B of size 3 * 2
B = [5 10; 15 20; 25 30];
println(isassigned(B, 25))
    
# test whether the given index value 9 is
# present in the 3D array C of size 2 * 2*4
C = cat([1 2; 3 4], [5 6; 7 8], 
        [9 10; 11 12], [13 14; 15 16], dims = 3);
println(isassigned(C, 9))

输出: