Open In App

Getting parent array of a specified array in Julia – parent() Method

Improve
Improve
Like Article
Like
Save
Share
Report

The parent() is an inbuilt function in julia which is used to return the parent array of a specified array view type (i.e, SubArray) or the array itself if it is not a view.

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.

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


Output:

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


Output:



Last Updated : 26 Mar, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads