Skip to content

Binary search #2147

Answered by agoose77
Durman asked this question in Q&A
Jan 20, 2023 · 1 comments · 5 replies
Discussion options

You must be logged in to vote

Hi @Durman!

Awkward Array does not yet have a direct function to compute positions within ragged arrays, which is what you appear to be looking for. However, we do have tools that let you build this yourself.

There are two ways of achieving this that I can think of. One is to use Numba, and the other is to flatten, search over the flattened list, and rebuild. I'll show both, but I would recommend the use of Numba for readability

1. Numba

The simplest approach that I can think of is to use np.searchsorted in Numba, and then employ ArrayBuilder to re-build the ragged result:

import numba as nb
import awkward as ak
import numpy as np

haystack = ak.Array([[0.0, 1.86, 2.93, 3.62, 4.9], [0.0, 0…

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@Durman
Comment options

@agoose77
Comment options

@Durman
Comment options

@agoose77
Comment options

@Durman
Comment options

Answer selected by Durman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants