parentindexes
parentindexes(A)
From an array view A
, returns the corresponding indexes in the parent
Examples
In the Julia programming language, the function parentindexes(A)
returns the corresponding indexes in the parent array view A
.
julia> A = reshape([1, 2, 3, 4, 5, 6], (2, 3))
2×3 reshape(::Vector{Int64}, 2, 3) with eltype Int64:
1 3 5
2 4 6
julia> parentindexes(A)
6-element Array{CartesianIndex{2},1}:
CartesianIndex(1, 1)
CartesianIndex(2, 1)
CartesianIndex(1, 2)
CartesianIndex(2, 2)
CartesianIndex(1, 3)
CartesianIndex(2, 3)
Here are some common examples of its use:
-
Obtain parent indexes from a reshaped array:
julia> A = reshape([1, 2, 3, 4, 5, 6], (2, 3)); julia> parentindexes(A) 6-element Array{CartesianIndex{2},1}: CartesianIndex(1, 1) CartesianIndex(2, 1) CartesianIndex(1, 2) CartesianIndex(2, 2) CartesianIndex(1, 3) CartesianIndex(2, 3)
This example shows how to retrieve the parent indexes from a reshaped array
A
. - Get parent indexes from a subarray view:
julia> A = [1 2 3; 4 5 6; 7 8 9]; julia> B = view(A, 2:3, 1:2); julia> parentindexes(B) 6-element Array{CartesianIndex{2},1}: CartesianIndex(2, 1) CartesianIndex(3, 1) CartesianIndex(2, 2) CartesianIndex(3, 2)
In this example, the
parentindexes
function is used to obtain the parent indexes from a subarray viewB
.
Note: The CartesianIndex
type represents a multi-dimensional index.
If the array view A
is not provided or is empty, the parentindexes
function will return an empty array.
See Also
Array, broadcast, cat, combinations, conj!, digits!, fieldnames, fill, fill!, last, length, maximum, minimum, ones, parent, parentindexes, partitions, permutations, pointer, pointer_to_array, promote_shape, rand!, reshape, scale, similar, sum, sum_kbn, takebuf_array, transpose!, vec, zeros,User Contributed Notes
Add a Note
The format of note supported is markdown, use triple backtick to start and end a code block.