Skip to content

Instantly share code, notes, and snippets.

@agoose77
Created July 9, 2021 19:39
Show Gist options
  • Save agoose77/e058a86f34228ef24b623dbb162f22fa to your computer and use it in GitHub Desktop.
Save agoose77/e058a86f34228ef24b623dbb162f22fa to your computer and use it in GitHub Desktop.
def pad_regular(array, pad_width, highlevel=True, behavior=None):
# If not regular, could convert to indexedarray and update indices
def apply(array):
array = ak.to_regular(array, highlevel=False)
local_ix = np.pad(np.arange(array.size), pad_width, mode="edge")
ix = np.lib.stride_tricks.as_strided(
local_ix, shape=(len(array), len(local_ix)), strides=(0,) + local_ix.strides
)
return array[ak.from_regular(ix)]
return apply_at_axis(array, apply, axis=-1, highlevel=highlevel, behavior=behavior)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment