creates nearest neighbour array