Re: [Numpy-discussion] Is there a defined way to "unpad" an array, and if not, should there be?

2021-04-13 Thread Evgeni Burovski
Prior art data point: scikit-image.util.crop : https://scikit-image.org/docs/dev/api/skimage.util.html#skimage.util.crop вт, 13 апр. 2021 г., 11:37 Eric Wieser : > Some other options here that avoid the need for a new function: > > * Add a `return_view` argument to `pad`, such that for

Re: [Numpy-discussion] Is there a defined way to "unpad" an array, and if not, should there be?

2021-04-13 Thread Eric Wieser
Some other options here that avoid the need for a new function: * Add a `return_view` argument to `pad`, such that for `padded, orig = np.pad(arr, ..., return_view=True)`, `orig == arr` and `orig.base is padded`. This is useful if `padded` is modified in place, but less useful otherwise. It has

Re: [Numpy-discussion] Is there a defined way to "unpad" an array, and if not, should there be?

2021-04-12 Thread Jeff Gostick
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

Re: [Numpy-discussion] Is there a defined way to "unpad" an array, and if not, should there be?

2021-04-12 Thread Stephan Hoyer
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,

Re: [Numpy-discussion] Is there a defined way to "unpad" an array, and if not, should there be?

2021-04-12 Thread Jeff Gostick
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

Re: [Numpy-discussion] Is there a defined way to "unpad" an array, and if not, should there be?

2021-04-12 Thread Aaron Meurer
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 >

Re: [Numpy-discussion] Is there a defined way to "unpad" an array, and if not, should there be?

2021-04-12 Thread Jeff Gostick
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

Re: [Numpy-discussion] Is there a defined way to "unpad" an array, and if not, should there be?

2021-04-12 Thread Stephan Hoyer
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

Re: [Numpy-discussion] Is there a defined way to "unpad" an array, and if not, should there be?

2021-04-12 Thread Benjamin Root
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