# Double indexing - wondering what's going on

**URL:** <https://discourse.julialang.org/t/double-indexing-wondering-whats-going-on/23777>\
**Category:** General Usage\
**Created:** [May 2, 2019, 1:46pm UTC](https://discourse.julialang.org/t/double-indexing-wondering-whats-going-on/23777 "2019-05-02T13:46:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ezgikurt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ezgikurt/32/7017_2.png) [@ezgikurt](https://discourse.julialang.org/u/ezgikurt)\
**Post date:** [May 2, 2019, 1:46pm UTC](https://discourse.julialang.org/t/double-indexing-wondering-whats-going-on/23777/1 "2019-05-02T13:46:24Z")

</div>

Hi, I came upon this issue in one of my functions and wondering what’s going on in the background. I am trying to reassign some elements in an array, but this does not work when I use double indexing (see below for a simple example

```julia
y = [missing;3;1]
nonmis = y.!==missing;
y[nonmis][1] = 4

```

However `y[nonmis][1]` still returns 3. I have modified my code so this is not an issue but I am just curious why.

If I index an array in the second index I realized this returns not an Array but a `view(::Array{Union{Missing,Float64},1}, [index])` so perhaps this is related.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [May 2, 2019, 2:11pm UTC](https://discourse.julialang.org/t/double-indexing-wondering-whats-going-on/23777/2 "2019-05-02T14:11:26Z")

</div>

> [@ezgikurt](#):
>
> y[nonmis][1] = 4

First `y[nonmis]` creates a new array and copies the indexed data into it, then the first element of this new array is set to 4. Then the new array goes out of scope and the change is lost. If you want `y` to be changed you need the first indexing to return a reference instead of a copy, which either of these do:

```julia
(@view y[nonmis])[1] = 4
@views y[nonmis][1] = 4

```

---

<div class="post-metadata">

**Author:** ![ezgikurt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ezgikurt/32/7017_2.png) [@ezgikurt](https://discourse.julialang.org/u/ezgikurt)\
**Post date:** [May 2, 2019, 2:15pm UTC](https://discourse.julialang.org/t/double-indexing-wondering-whats-going-on/23777/3 "2019-05-02T14:15:29Z")

</div>

great thank you!
