# Help with NearestNeighbours and array reduction

**URL:** <https://discourse.julialang.org/t/help-with-nearestneighbours-and-array-reduction/43094>\
**Category:** Performance\
**Created:** [July 15, 2020, 1:13am UTC](https://discourse.julialang.org/t/help-with-nearestneighbours-and-array-reduction/43094 "2020-07-15T01:13:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sparrowhawk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sparrowhawk/32/9148_2.png) [@sparrowhawk](https://discourse.julialang.org/u/sparrowhawk)\
**Post date:** [July 15, 2020, 1:13am UTC](https://discourse.julialang.org/t/help-with-nearestneighbours-and-array-reduction/43094/1 "2020-07-15T01:13:30Z")

</div>

Hi,

I’m trying to find a list of points within range of given co-ordinates, using `NearestNeighbours`

```julia
using NearestNeighbors
coords = [0. 1
          0 1]
balltree = BallTree(coords)
rsearch = 1.0
points = [0.5, 0.5] 
idxs = inrange(balltree, points, rsearch, true) # shows [1, 2] as expected

```

but if I have multiple points

```julia
points = [0.5 1.5 
          0.5 1.5]
idxs = inrange(balltree, points, rsearch, true) # shows [[1, 2], [2]] as expected

```

But I don’t want to revisit indices in the tree already visited, if it is already within range of a point. So what I want is either of

```julia
idxs = unique(vcat(inrange(balltree, points, rsearch, true)...)) # provides [1, 2]
idxs = unique(reduce(vcat, inrange(balltree, points, rsearch, true))) # provides [1, 2]

```

But this concatenation is expensive. Is there a way to get around this? Is it possible to skip a tree co-ordinate if it has already been visited and just provide a vector of indices? I understand you can do this with `knn` but not with `balltree`.

Thanks
