Created
May 1, 2013 05:37
-
-
Save JDWarner/5493906 to your computer and use it in GitHub Desktop.
Utility function for padding an array by appending `pad_amt` zeros along any `axis`. Non-symmetric. The ideas behind this snippet led to the `np.pad` improvements introduced in NumPy 1.8. This is licensed under the modified BSD.
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
import numpy as np | |
def _pad_asymmetric_zeros(arr, pad_amt, axis=-1): | |
"""Pads `arr` by `pad_amt` along specified `axis`""" | |
if axis == -1: | |
axis = arr.ndim - 1 | |
zeroshape = tuple([x if i != axis else pad_amt | |
for (i, x) in enumerate(arr.shape)]) | |
return np.concatenate((arr, np.zeros(zeroshape, dtype=arr.dtype)), | |
axis=axis) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment