# How to index array at multiple locations

**URL:** <https://discourse.julialang.org/t/how-to-index-array-at-multiple-locations/84142>\
**Category:** New to Julia\
**Tags:** indexing\
**Created:** [July 13, 2022, 2:07am UTC](https://discourse.julialang.org/t/how-to-index-array-at-multiple-locations/84142 "2022-07-13T02:07:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![v715](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/v715/32/37202_2.png) [@v715](https://discourse.julialang.org/u/v715)\
**Post date:** [July 13, 2022, 2:07am UTC](https://discourse.julialang.org/t/how-to-index-array-at-multiple-locations/84142/1 "2022-07-13T02:07:45Z")

</div>

Say I have a n-by-n array and I want to index at a bunch of places

If I was in numpy, I would do something like `A[[1,1], [2, 5], [92, 2], [4, 10]`

But this doesn’t work in Julia. Is there a way to do this??

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [July 13, 2022, 2:10am UTC](https://discourse.julialang.org/t/how-to-index-array-at-multiple-locations/84142/2 "2022-07-13T02:10:56Z")

</div>

One way is to use CartesianIndex

```julia
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

```

---

<div class="post-metadata">

**Author:** ![v715](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/v715/32/37202_2.png) [@v715](https://discourse.julialang.org/u/v715)\
**Post date:** [July 13, 2022, 2:17am UTC](https://discourse.julialang.org/t/how-to-index-array-at-multiple-locations/84142/3 "2022-07-13T02:17:52Z")

</div>

ah cool! and it works with `@views`. thanks!
