當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。