# Faster array indexing with a logical array

**URL:** <https://discourse.julialang.org/t/faster-array-indexing-with-a-logical-array/47364>\
**Category:** New to Julia\
**Tags:** array\
**Created:** [September 27, 2020, 3:24pm UTC](https://discourse.julialang.org/t/faster-array-indexing-with-a-logical-array/47364 "2020-09-27T15:24:04Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![mcabbott](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mcabbott/32/6603_2.png) [@mcabbott](https://discourse.julialang.org/u/mcabbott)\
**Post date:** [September 27, 2020, 4:27pm UTC](https://discourse.julialang.org/t/faster-array-indexing-with-a-logical-array/47364/3 "2020-09-27T16:27:57Z")

</div>

You don’t need `findall`, you can index with the boolean array from broadcasting `.<` (as in the python version). But even better is to avoid creating the sum anywhere:

```julia
julia> gb1(x) = x[vec(sum(x,dims=2) .< 1), :];

julia> gb2(x) = x[(@views x[:,1] .+ x[:,2] .< 1), :];

julia> @btime gb1($points);
  30.618 μs (13 allocations: 160.41 KiB)

julia> @btime gb2($points);
  20.707 μs (5 allocations: 82.00 KiB)

julia> @btime getindicesVectorized($points); # to compare
  37.253 μs (15 allocations: 275.02 KiB)

```

---

_[View the full topic](https://discourse.julialang.org/t/faster-array-indexing-with-a-logical-array/47364)._
