Proposed new feature or change:
Mailing list post
It is common to want to pad an array along a specific axis. Examples:
Doing so with numpy.pad requires constructing a list of pairs of length equal to the ndim of the array, with exactly one of those pairs at the right position containing the desired pad widths. This can be verbose and cumbersome when there are several axes.
I propose a new, more user-friendly way to pad along a specific axis (or axes): Let the pad_width argument accept a dictionary whose keys are axes and whose values are the (before, after) pair (or perhaps single number) for the corresponding axis. Example:
# before
np.pad(array, [(0, 0), (0, 0), (1, 2), (0, 0), (0, 0)])
# after
np.pad(array, {-3: (1, 2)})
This should require only minor modification to the implementation of numpy.pad. If others like this idea, I can create a PR for it.
Proposed new feature or change:
Mailing list post
It is common to want to pad an array along a specific axis. Examples:
Doing so with
numpy.padrequires constructing a list of pairs of length equal to the ndim of the array, with exactly one of those pairs at the right position containing the desired pad widths. This can be verbose and cumbersome when there are several axes.I propose a new, more user-friendly way to pad along a specific axis (or axes): Let the
pad_widthargument accept a dictionary whose keys are axes and whose values are the(before, after)pair (or perhaps single number) for the corresponding axis. Example:This should require only minor modification to the implementation of
numpy.pad. If others like this idea, I can create a PR for it.