# Is there a destructive version of logical indexing?

**URL:** <https://discourse.julialang.org/t/is-there-a-destructive-version-of-logical-indexing/37428>\
**Category:** New to Julia\
**Created:** [April 12, 2020, 12:42am UTC](https://discourse.julialang.org/t/is-there-a-destructive-version-of-logical-indexing/37428 "2020-04-12T00:42:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [April 12, 2020, 12:42am UTC](https://discourse.julialang.org/t/is-there-a-destructive-version-of-logical-indexing/37428/1 "2020-04-12T00:42:39Z")

</div>

I often deal with both: (1) arrays of indexes of some other array; (2) bitmasks of some other array.

I can use the array of indexes to delete positions inplace with:

```julia
deleteat!(array, array_of_indexes_of_first_array)

```

but I cannot do the same with a bitarray:

```julia
deleteat!(array, bitarray_of_same_size_as_first_array) # error
filter!(bitarray_of_same_size_as_first_array, array) # error

```

I need to update the object, not just change bindings, so I cannot:

```julia
array = array[bitarray_of_same_size_as_first_array]

```

I can do this however:

```julia
deleteat!(array, keys(array)[bitarray_of_same_size_as_first_array])

```

but it makes me wonder if there is a standard library method that I am overlooking.

---

<div class="post-metadata">

**Author:** ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)\
**Post date:** [April 12, 2020, 12:49am UTC](https://discourse.julialang.org/t/is-there-a-destructive-version-of-logical-indexing/37428/2 "2020-04-12T00:49:27Z")

</div>

What version of Julia are you on? The following works on Julia 1.4:

```julia
julia> x = [1, 2, 3]; deleteat!(x, BitArray([0, 1, 0]))
2-element Array{Int64,1}:
 1
 3

julia> x = [1, 2, 3]; deleteat!(x, [false, true, false])
2-element Array{Int64,1}:
 1
 3

```

---

<div class="post-metadata">

**Author:** ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)\
**Post date:** [April 12, 2020, 12:58am UTC](https://discourse.julialang.org/t/is-there-a-destructive-version-of-logical-indexing/37428/3 "2020-04-12T00:58:00Z")

</div>

Ouch, I was using 1.0.5 until last week, but decided to support only 1.4+ since then. I was already accustomed to stumble in this problem and did not occur to me to “write it in the way I already know it does not work” again to test if it worked in the new version. Thank you, my code will be effortlessly more readable now.
