How to index array at multiple locations

One way is to use CartesianIndex

julia> a = rand(3,3)
3×3 Matrix{Float64}:
 0.882002  0.04332   0.477523
 0.829209  0.425031  0.0362383
 0.303801  0.161715  0.422988

julia> a[[CartesianIndex(1,1), CartesianIndex(3,3)]]
2-element Vector{Float64}:
 0.8820020685738753
 0.4229883416619057
1 Like