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

Stephan Hoyer shoyer at gmail.com
Mon Apr 12 21:15:23 EDT 2021

On Mon, Apr 12, 2021 at 5:12 PM Jeff Gostick <jgostick at gmail.com> 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, but they all require more than a little bit of thought
> and care, are dependent on array shape, and honestly error prone.  It would
> be very valuable to me to have such a 'predefined' function, so I was
> wondering if (a) I was unaware of some function that already does this and
> (b) if I'm alone in thinking this would be useful.

Indeed, this is a fair question.

Given that this is not entirely trivial to write correctly, I think it
would be reasonable to add the inverse operation for pad() into NumPy. This
is generally better than encouraging users to write their own thing.

>From a naming perspective, here are some possibilities:

I think "trim" would be pretty descriptive, probably slightly better than
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.python.org/pipermail/numpy-discussion/attachments/20210412/224e4b1e/attachment.html>

More information about the NumPy-Discussion mailing list