📜  获取 Julia 中数组的元素个数 - length() 方法

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

获取 Julia 中数组的元素个数 - length() 方法

length()是 julia 中的内置函数,用于返回指定数组中存在的元素数。

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

输出: