Is there a destructive version of logical indexing?

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:

deleteat!(array, array_of_indexes_of_first_array)

but I cannot do the same with a bitarray:

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:

array = array[bitarray_of_same_size_as_first_array]

I can do this however:

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.

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

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
2 Likes

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.

2 Likes