I am wondering why the not operator isn't working with array broadcasting/element-wise operations. For example, if I enter
x = Array{Any}([1,2,3,4,missing,6])
!ismissing.(x)
I get an error ERROR: MethodError: no method matching !(::BitArray{1})
but if I try ismissing.(x) it works fine,
ismissing.(x)
#out > 6-element BitArray{1}: 0 0 0 0 1 0
and typing without the broadcasting works as a whole as well (one output for the entire array)
!ismissing(x)
#out > True
So I am wondering if there is a possibility to get a similar result as using the "!" operator.
You need to also broadcast !
to each element:
julia> x = Array{Any}([1,2,3,4,missing,6]);
julia> .!(ismissing.(x)) # the . comes before operators (!, +, -, etc)
6-element BitVector:
1
1
1
1
0
1
For this specific case you can instead negate the function before broadcasting:
julia> (!ismissing).(x)
6-element BitVector:
1
1
1
1
0
1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With