# Is it possible to delete a row or column from a multi-dimensional array in-place?

**URL:** <https://discourse.julialang.org/t/is-it-possible-to-delete-a-row-or-column-from-a-multi-dimensional-array-in-place/54182>\
**Category:** General Usage\
**Created:** [January 29, 2021, 1:46pm UTC](https://discourse.julialang.org/t/is-it-possible-to-delete-a-row-or-column-from-a-multi-dimensional-array-in-place/54182 "2021-01-29T13:46:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![BridgeBot](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bridgebot/32/21491_2.png) [@BridgeBot](https://discourse.julialang.org/u/BridgeBot)\
**Post date:** [January 29, 2021, 1:46pm UTC](https://discourse.julialang.org/t/is-it-possible-to-delete-a-row-or-column-from-a-multi-dimensional-array-in-place/54182/1 "2021-01-29T13:46:22Z")

</div>

Hey guys, is it possible to delete a row or column from a multi-dimensional array (say a matrix) “in-place”? Somewhat similar to what `deleteat!` does for vectors. I guess the answer is no but I thought I’d ask (and test our new bridging system 🌉 ). Thanks in advance. (second attempt :D)

[(Original message :slack:)](https://julialang.slack.com/archives/C6A044SQH/p1611927980089900)

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [January 29, 2021, 2:15pm UTC](https://discourse.julialang.org/t/is-it-possible-to-delete-a-row-or-column-from-a-multi-dimensional-array-in-place/54182/2 "2021-01-29T14:15:59Z")

</div>

No, that is not possible.

Perhaps a matrix isn’t the correct structure? This is very easy to do in DataFrames

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [January 29, 2021, 3:06pm UTC](https://discourse.julialang.org/t/is-it-possible-to-delete-a-row-or-column-from-a-multi-dimensional-array-in-place/54182/3 "2021-01-29T15:06:58Z")

</div>

```julia
julia> a = [1 2; 3 4]
2×2 Array{Int64,2}:
 1 2
 3 4
julia> reshape(resize!(vec(a), length(a) - size(a, 1)), size(a, 1), :)
2×1 Array{Int64,2}:
 1
 3

```

It is possible, as was mentioned on slack.

This also generalizes:

> Simeon Schaub:  
> Yes, you can just replace `size(a, 1)` with `size(a)[2:end]...` to always resize the last dimension of a higher-dimensional array

> crstnbr:  
> That’s something. But it only works for the last dimension. What about the generic case, i.e dropping, say, the second column of a 1x2x3x4 sized array?

> Simeon Schaub:  
> You should be able to use a similar approach there as well. You just need to convert whatever you want to delete to linear indices and then you can use `deleteat!` after reshaping to a vector with `vec`

The answers don’t show up here because the bridge bot is not that smart yet.

---

<div class="post-metadata">

**Author:** ![ChrisRackauckas](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chrisrackauckas/32/77_2.png) [@ChrisRackauckas](https://discourse.julialang.org/u/ChrisRackauckas)\
**Post date:** [January 29, 2021, 3:26pm UTC](https://discourse.julialang.org/t/is-it-possible-to-delete-a-row-or-column-from-a-multi-dimensional-array-in-place/54182/4 "2021-01-29T15:26:54Z")

</div>

You can take a view.

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [January 29, 2021, 6:23pm UTC](https://discourse.julialang.org/t/is-it-possible-to-delete-a-row-or-column-from-a-multi-dimensional-array-in-place/54182/5 "2021-01-29T18:23:29Z")

</div>

For those finding this post via Discourse - it is only bridged Slack → Discourse, not the other way around…
