当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Julia isassigned()用法及代码示例


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

用法: isassigned(array, i)

参数:

  • array:指定数组
  • i:指定索引值

返回值:如果指定的索引值存在于数组中,则返回 true,否则返回 false。

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

输出:




相关用法


注:本文由纯净天空筛选整理自Kanchan_Ray大神的英文原创作品 Check if a specific index of an array contains a value in Julia – isassigned() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。