parent()
是 julia 中的内置函数,用于返回指定数组视图类型(即 SubArray)的父数组或数组本身(如果它不是视图)。
Syntax: parent(A)
Parameters:
- A: Specified array or an array view type.
Returns: It returns the parent array of a specified array view type (i.e, SubArray) or the array itself if it is not a view.
示例 1:
# Julia program to illustrate
# the use of Array parent() method
# Getting the parent array of the
# specified 1D array view type (i.e, SubArray)
# or the array itself if it is not a view.
A = [1, 2, 3, 4];
B = view(A, 2)
println(parent(B))
# Getting the parent array of the
# specified 2D array view type (i.e, SubArray)
# or the array itself if it is not a view.
C = [1 2; 3 4];
D = view(C, 1:2,: )
println(parent(D))
输出:
示例 2:
# Julia program to illustrate
# the use of Array parent() method
# Getting the parent array of the
# specified 1D array view type (i.e, SubArray)
# or the array itself if it is not a view.
A = [1, 2, 3, 4];
println(parent(A))
# Getting the parent array of the
# specified 2D array view type (i.e, SubArray)
# or the array itself if it is not a view.
B = [1 2; 3 4];
println(parent(B))
# Getting the parent array of the
# specified 3D array view type (i.e, SubArray)
# or the array itself if it is not a view.
C = cat([1 2; 3 4], [5 6; 7 8], [2 2; 3 4], dims = 3);
println(parent(C))
输出: