Open In App
Related Articles

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

Improve Article
Improve
Save Article
Save
Like Article
Like

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:


Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 26 Mar, 2020
Like Article
Save Article
Previous
Next
Similar Reads