# Negation of boolean array

**URL:** https://discourse.julialang.org/t/negation-of-boolean-array/16159
**Category:** General Usage
**Created:** [October 11, 2018, 7:57am UTC](https://discourse.julialang.org/t/negation-of-boolean-array/16159 "2018-10-11T07:57:06Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [October 11, 2018, 7:57am UTC](https://discourse.julialang.org/t/negation-of-boolean-array/16159/1 "2018-10-11T07:57:06Z")

</div>

This is a slightly silly question I guess, but I spent more time trying to figure this out now than I should have so here goes: what’s the idiomatic way to negate an Array of Bools?

```julia
julia> !true
false

julia> a = [true false]
1×2 Array{Bool,2}:
 true false

julia> !a
ERROR: MethodError: no method matching !(::Array{Bool,2})
Closest candidates are:
  !(::Missing) at missing.jl:79
  !(::Bool) at bool.jl:35
  !(::Function) at operators.jl:853
Stacktrace:
 [1] top-level scope at none:0

julia> !.a
ERROR: syntax: invalid identifier name "."

julia> [!i for i in a] # works but seems slightly verbose?
1×2 BitArray{2}:
 false true

```

I then tried to work out what `!` actually does under the hood and obtained this solution:

```julia
julia> @code_lowered !true
CodeInfo(
35 1 ─ nothing │
36 │ %2 = (Base.not_int)(x) │
   └── return %2 │
)

julia> Base.not_int.(a)
1×2 BitArray{2}:
 false true

```

Is there some way to just apply `!` directly to an array?

---

<div class="post-metadata">

### Author: ![kdyrhage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kdyrhage/32/2326_2.png) [@kdyrhage](https://discourse.julialang.org/u/kdyrhage)
#### Post date: [October 11, 2018, 8:01am UTC](https://discourse.julialang.org/t/negation-of-boolean-array/16159/2 "2018-10-11T08:01:31Z")

</div>

`!` is an operator, so the dot goes before it:

```julia
.!a

```
