# Fastest way to negate some booleans in an array

**URL:** <https://discourse.julialang.org/t/fastest-way-to-negate-some-booleans-in-an-array/89261>\
**Category:** Performance\
**Tags:** boolean\
**Created:** [October 25, 2022, 9:10pm UTC](https://discourse.julialang.org/t/fastest-way-to-negate-some-booleans-in-an-array/89261 "2022-10-25T21:10:00Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![aplavin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aplavin/32/222056_2.png) [@aplavin](https://discourse.julialang.org/u/aplavin)\
**Post date:** [October 25, 2022, 9:58pm UTC](https://discourse.julialang.org/t/fastest-way-to-negate-some-booleans-in-an-array/89261/4 "2022-10-25T21:58:49Z")

</div>

> [@HMegh](#):
>
> `map!(!,A[2:2:end],A[2:2:end])`

Just use views and this becomes much more efficient:

```julia
@views map!(!,A[2:2:end],A[2:2:end])

```

Or use broadcasting, even faster:

```julia
A[2:2:end] .= .!(@view A[2:2:end])

```

---

_[View the full topic](https://discourse.julialang.org/t/fastest-way-to-negate-some-booleans-in-an-array/89261)._
