Skip to content

Instantly share code, notes, and snippets.

@agoose77
Created February 27, 2022 20:41
Show Gist options
  • Save agoose77/6c6771e814669338d0f7a3e3ae7c47fc to your computer and use it in GitHub Desktop.
Save agoose77/6c6771e814669338d0f7a3e3ae7c47fc to your computer and use it in GitHub Desktop.
def choose(a, choices, mode="raise", highlevel=True, behavior=None):
def getfunction(inputs, depth):
if not all(x.purelist_depth == 1 for x in inputs):
return
arrays = [nplike.asarray(x) for x in inputs]
a = arrays[0]
choices = arrays[1:]
out = np.choose(a, choices, mode=mode)
return lambda: (ak.layout.NumpyArray(out),)
arrays = [a, *choices]
inputs = [ak.to_layout(x) for x in arrays]
nplike = ak.nplike.of(arrays)
behavior = ak._util.behaviorof(arrays, behavior=behavior)
out, = ak._util.broadcast_and_apply(inputs, getfunction, behavior)
return ak._util.maybe_wrap(out, behavior, highlevel)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment