获取Julia中的数组维度和维度的大小 - size() 方法
size()
是 julia 中的内置函数,用于返回包含指定数组维度的元组。这个返回的元组格式是 (a, b, c) 其中 a 是行,b 是列,c 是数组的高度。
Syntax:
size(A::AbstractArray)
or
size(A::AbstractArray, Dim)
Parameters:
- A: Specified array
- Dim: Specified dimension
Returns: It returns a tuple containing the dimensions of the specified array.
示例 1:
# Julia program to illustrate
# the use of Array size() method
# Finding a tuple containing the dimension of
# the specified 1D array A.
A = [5, 10, 15, 20]
println(size(A))
# Finding a tuple containing the dimension of
# the specified 2D array B of size 2*2
B = [5 10; 15 20]
println(size(B))
# Finding a tuple containing the dimension of
# 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(size(C))
输出:
示例 2:
# Julia program to illustrate
# the use of Array size() method
# Finding a tuple containing the dimension of
# the specified 1D array A.
A = [1, 2, 3];
println(size(A, 3))
# Finding a tuple containing the dimension of
# the specified 2D array B of size 3*2
B = [2 4; 6 8; 10 12];
println(size(B, 2))
# Finding a tuple containing the dimension of
# the specified 3D array C of size 2*2*4
C = cat([10 15; 20 25], [30 35; 40 45],
[50 55; 60 65], [70 75; 80 85], dims=3);
println(size(C, 2))
输出: