It is great to hear that this might be useful. I would LOVE to create a PR
on this idea and contribute back to numpy...but let's not get ahead of
ourselves :-)
Regarding the name, I kinda like "unpad" since it relates directly to
"pad", analogous to "ravel" and "unravel" for instance. Or maybe "
On Mon, Apr 12, 2021 at 5:12 PM Jeff Gostick wrote:
> I guess I should have clarified that I was inquiring about proposing a
> 'feature request'. The github site suggested I open a discussion on this
> list first. There are several ways to effectively unpad an array as has
> been pointed out, b
I guess I should have clarified that I was inquiring about proposing a
'feature request'. The github site suggested I open a discussion on this
list first. There are several ways to effectively unpad an array as has
been pointed out, but they all require more than a little bit of thought
and care
On Mon, Apr 12, 2021 at 2:29 PM Stephan Hoyer wrote:
>
> The easy way to unpad an array is by indexing with slices, e.g., x[20:-4] to
> undo a padding of [(20, 4)]. Just be careful about unpadding "zero" elements
> on the right hand side, because Python interprets an ending slice of zero
> diff
It's definitely just "slicing", but it's a bit inconvenient. I'm thinking
more like:
arr = np.random.rand(10, 10, 10)
W = [[3, 2], [4, 6]] # or W = 4, or W = [4, 5]
arr_padded = np.pad(arr, pad_width=W)
< Do some stuff to arr_padded >
arr = np.unpad(arr_padded, pad_width=W) # Using W just works
The easy way to unpad an array is by indexing with slices, e.g., x[20:-4]
to undo a padding of [(20, 4)]. Just be careful about unpadding "zero"
elements on the right hand side, because Python interprets an ending slice
of zero differently -- you need to write something like x[20:] to undo
padding
Isn't that just slicing? Or perhaps you are looking for a way to simplify
the calculation of the slice arguments from the original pad arguments?
On Mon, Apr 12, 2021 at 4:15 PM Jeff Gostick wrote:
> I often find myself padding an array to do some processing on it (i.e. to
> avoid edge artifacts
I often find myself padding an array to do some processing on it (i.e. to
avoid edge artifacts), then I need to remove the padding. I wish there was
either a built in "unpad" function that accepted the same arguments as
"pad", or that "pad" accepted negative numbers (e.g [-20, -4] would undo a
pad