# Can you remove an element from a multidimensal array?

Suppose if I had a 2 dimensional array:

``````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, it talks about deleting a row rather than an element.

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

3 Likes

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?

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,.

``````a[2,1] = 12345
``````
7 Likes

``````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
``````
1 Like

Or you could use some other kind of container, eg

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

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.

1 Like