# Can you remove an element from a multidimensal array?

**URL:** <https://discourse.julialang.org/t/can-you-remove-an-element-from-a-multidimensal-array/48386>\
**Category:** New to Julia\
**Created:** [October 14, 2020, 7:15pm UTC](https://discourse.julialang.org/t/can-you-remove-an-element-from-a-multidimensal-array/48386 "2020-10-14T19:15:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon60034542](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@anon60034542](https://discourse.julialang.org/u/anon60034542)\
**Post date:** [October 14, 2020, 7:15pm UTC](https://discourse.julialang.org/t/can-you-remove-an-element-from-a-multidimensal-array/48386/1 "2020-10-14T19:15:11Z")

</div>

Suppose if I had a 2 dimensional array:

```julia
a = Int32[1 2 3 4; 5 6 7 8; 9 10 11 12]

```

If I wanted to delete the first element in the second row, can I do that?

I attempted to search for myself and I found this Stack Overflow [page](https://stackoverflow.com/a/17299817), it talks about deleting a row rather than an element.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [October 14, 2020, 7:18pm UTC](https://discourse.julialang.org/t/can-you-remove-an-element-from-a-multidimensal-array/48386/2 "2020-10-14T19:18:31Z")

</div>

> [@anon60034542](#):
>
> If I wanted to delete the first element in the second row, can I do that?

What does that mean? What resulting array do you want?

---

<div class="post-metadata">

**Author:** ![anon60034542](https://avatars.discourse-cdn.com/v4/letter/a/90ced4/32.png) [@anon60034542](https://discourse.julialang.org/u/anon60034542)\
**Post date:** [October 14, 2020, 7:28pm UTC](https://discourse.julialang.org/t/can-you-remove-an-element-from-a-multidimensal-array/48386/3 "2020-10-14T19:28:51Z")

</div>

I’m guessing by your question that I can’t just remove an element, I would have to remove and replace an element, correct?

I guess my question should be can I remove `5` and replace it with another number?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [October 14, 2020, 7:36pm UTC](https://discourse.julialang.org/t/can-you-remove-an-element-from-a-multidimensal-array/48386/4 "2020-10-14T19:36:28Z")

</div>

> [@anon60034542](#):
>
> I’m guessing by your question that I can’t just remove an element

A 2d array is a data structure that has the same number of elements in every row, so it’s not meaningful to “remove an element” — the result would no longer be an array,.

> [@anon60034542](#):
>
> I guess my question should be can I remove `5` and replace it with another number?

```julia
a[2,1] = 12345

```

---

<div class="post-metadata">

**Author:** ![Adriel](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@Adriel](https://discourse.julialang.org/u/Adriel)\
**Post date:** [October 14, 2020, 10:52pm UTC](https://discourse.julialang.org/t/can-you-remove-an-element-from-a-multidimensal-array/48386/5 "2020-10-14T22:52:03Z")

</div>

Maybe this is helpful?

```julia
julia> a = Union{Int32,Missing}[1 2 3 4; 5 6 7 8; 9 10 11 12];

julia> a[2,1] = missing;

julia> a
3×4 Array{Union{Missing, Int32},2}:
 1 2 3 4
  missing 6 7 8
 9 10 11 12

```

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [October 16, 2020, 8:42am UTC](https://discourse.julialang.org/t/can-you-remove-an-element-from-a-multidimensal-array/48386/6 "2020-10-16T08:42:47Z")

</div>

Or you could use some other kind of container, eg

```julia
a = Int32[1 2 3 4; 5 6 7 8; 9 10 11 12]
d = Dict([i => a[i] for i in CartesianIndices(a)])
delete!(d, CartesianIndex(2, 1))

```

---

<div class="post-metadata">

**Author:** ![Per](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/per/32/10387_2.png) [@Per](https://discourse.julialang.org/u/Per)\
**Post date:** [October 16, 2020, 9:14am UTC](https://discourse.julialang.org/t/can-you-remove-an-element-from-a-multidimensal-array/48386/7 "2020-10-16T09:14:02Z")

</div>

It’s maybe worth mentioning that some languages (notably Javascript) use the word “array” to refer to what in Julia would be a `Dict`. A Julia `Array` is more akin to a Fortran array, which is a much simpler construction.
