📜  Julia中获取指定数组的父数组——parent()方法

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

parent()是 julia 中的内置函数,用于返回指定数组视图类型(即 SubArray)的父数组或数组本身(如果它不是视图)。

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

输出: