Created
July 9, 2021 19:39
-
-
Save agoose77/e058a86f34228ef24b623dbb162f22fa to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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