A bit silly question, but I couldn’t find anything on how to (properly) invert bits in a BitArray
?
The only way I made it work is through
a = 1:3 .== 2 # false true false
(!).(a) # true false true
but this doesn’t look pretty.
A bit silly question, but I couldn’t find anything on how to (properly) invert bits in a BitArray
?
The only way I made it work is through
a = 1:3 .== 2 # false true false
(!).(a) # true false true
but this doesn’t look pretty.
I think (!).(a)
is not that bad. Personally I find map(!, a)
easier to read then the broadcast.
Depending on the surrounding code a .== false
may or may not be clearer.
This is a slightly better, IMO:
julia> @. !a
3-element BitArray{1}:
true
false
true
Or simply:
julia> .!a
3-element BitArray{1}:
true
false
true
Well, this is the solution
But this is completely counterintuitive comparing to broadcast of an ordinary function.
@jw3126 map(!, a)
also looks good, thank you!
Well, when broadcasting, the dot comes always in front of operators, says here