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


Julia length()用法及代碼示例


這個length()是 julia 中的一個內置函數,用於返回指定數組中存在的元素數。

用法: length(A::AbstractArray)

參數:

  • A:指定數組

返回值:它返回指定數組中存在的元素數。

範例1:




# Julia program to illustrate 
# the use of Array length() method
   
# Finding the number of elements present in
# the specified 1D array A.
A = [5, 10, 15, 20]
println(length(A))
   
# Finding the number of elements present in
# the specified 2D array B of size 2 * 2
B = [5 10; 15 20]
println(length(B))
   
# Finding the number of elements present in
# the specified 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(length(C))

輸出:

範例2:


# Julia program to illustrate 
# the use of Array length() method
    
# Finding the number of elements present in
# the specified 1D array A.
A = [1, 2, 3];
println(length(A))
    
# Finding the number of elements present in
# the specified 2D array B of size 2 * 2
B = [2 4; 6 8; 10 12];
println(length(B))
    
# Finding the number of elements present in
# the specified 3D array C of size 2 * 2*2
C = cat([1 2; 3 4], [5 6; 7 8], 
        [9 10; 11 12], [13 14; 15 16], dims = 4);
println(length(C))

輸出:




相關用法


注:本文由純淨天空篩選整理自Kanchan_Ray大神的英文原創作品 Get number of elements of array in Julia – length() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。