Slicing and merging of CartesianIndices

You can do use ci.indices though I think that’s an undocumented internal:

ci1 = CartesianIndices(ci.indices[1])
ci2 = CartesianIndices(ci.indices[2])

You can get the same information with first(ci), step(ci), last(ci) but that’s less convenient.

To recover the full list:

CartesianIndices((ci1.indices[1], ci2.indices[1]))

Another idea using arrays of CartesianIndex rather than CartesianIndices:

julia> i1 = getindex.(ci[:, 1], 1)
3-element Vector{Int64}:
 2
 4
 6

julia> i2 = getindex.(ci[1, :], 2)
3-element Vector{Int64}:
 3
 6
 9

julia> CartesianIndex.(i1, i2')
3×3 Matrix{CartesianIndex{2}}:
 CartesianIndex(2, 3)  CartesianIndex(2, 6)  CartesianIndex(2, 9)
 CartesianIndex(4, 3)  CartesianIndex(4, 6)  CartesianIndex(4, 9)
 CartesianIndex(6, 3)  CartesianIndex(6, 6)  CartesianIndex(6, 9)
1 Like