📜  在 Julia 中获取数组元素的数量 – length() 方法

📅  最后修改于: 2021-11-25 04:46:03             🧑  作者: Mango

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

输出: