<div dir="auto"><div dir="auto">Prior art data point: scikit-image.util.crop :</div><div dir="auto"><br></div><a href="https://scikit-image.org/docs/dev/api/skimage.util.html#skimage.util.crop">https://scikit-image.org/docs/dev/api/skimage.util.html#skimage.util.crop</a><div dir="auto"><br></div><div dir="auto"><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">вт, 13 апр. 2021 г., 11:37 Eric Wieser <<a href="mailto:wieser.eric%2Bnumpy@gmail.com">wieser.eric+numpy@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Some other options here that avoid the need for a new function:<br><br>* 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 the advantage of not having to recompute the slices, as pad already has them.<div>* Accept a `slice` object directly in `np.pad`; for `sl = np.s_[2:-20, 4:-40]`, `padded = np.pad(array, sl)`, we have `padded[sl] == array`.</div><div><br></div><div>The second idea seems promising to me, but perhaps there are corner cases I haven't thought of that it wouldn't help with.</div><div><br></div><div>Eric</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, 13 Apr 2021 at 09:26, Ralf Gommers <<a href="mailto:ralf.gommers@gmail.com" target="_blank" rel="noreferrer">ralf.gommers@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Apr 13, 2021 at 3:37 AM Jeff Gostick <<a href="mailto:jgostick@gmail.com" target="_blank" rel="noreferrer">jgostick@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>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 :-)  <br></div><div><br></div><div>Regarding the name, I kinda like "unpad" since it relates directly to "pad", analogous to "ravel" and "unravel" for instance.  Or maybe "depad".  Although, it's possible to use this on any array, not just a previously padded one, so maybe tying it too directly to "pad" is not right, in which case "trim" and "crop" are both perfect.  I must admit that I find it odd that these functions are not in numpy 
already.  I just searched the docs and they show up as keyword args for a few functions but are otherwise conspicuously absent.  Also, funnily, there is a link to "padding arrays" but it is basically empty: <a href="https://numpy.org/doc/stable/reference/routines.padding.html" target="_blank" rel="noreferrer">https://numpy.org/doc/stable/reference/routines.padding.html</a>.</div><div><br></div><div>Alternatively, I don't hate the idea of passing negative pad widths into "pad".  I actually tried this at one point to see if there was a hidden functionality there, to no avail.  <br></div><div><br></div><div>BTW, we just adding a custom "unpad" function to our PoreSpy package for this purpose: <a href="https://github.com/PMEAL/porespy/blob/dev/porespy/tools/_unpadfunc.py" target="_blank" rel="noreferrer">https://github.com/PMEAL/porespy/blob/dev/porespy/tools/_unpadfunc.py</a></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 12, 2021 at 9:15 PM Stephan Hoyer <<a href="mailto:shoyer@gmail.com" target="_blank" rel="noreferrer">shoyer@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr">On Mon, Apr 12, 2021 at 5:12 PM Jeff Gostick <<a href="mailto:jgostick@gmail.com" target="_blank" rel="noreferrer">jgostick@gmail.com</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>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. </div></div></blockquote><div><br></div><div>Indeed, this is a fair question.</div><div><br></div><div>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.</div><div><br></div><div>From a naming perspective, here are some possibilities:</div><div>unpad</div><div>trim</div><div>crop</div><div><br></div><div>I think "trim" would be pretty descriptive, probably slightly better than "unpad."</div></div></div></blockquote></div></blockquote><div><br></div><div>I'm not a fan of `trim`. We already have `clip` which sounds similar. <br></div><div><br></div><div>`unpad` looks like the only one that's completely unambiguous. <br></div><div><br></div><div>`crop` sounds like an image processing function, and what we don't want is something like Pillow's `crop(left, top, right, bottom)`.</div><div><br></div><div>Cheers,<br></div><div>Ralf</div><div><br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@python.org" target="_blank" rel="noreferrer">NumPy-Discussion@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/numpy-discussion</a><br>
</blockquote></div>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@python.org" target="_blank" rel="noreferrer">NumPy-Discussion@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/numpy-discussion</a><br>
</blockquote></div></div>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@python.org" target="_blank" rel="noreferrer">NumPy-Discussion@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/numpy-discussion</a><br>
</blockquote></div>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@python.org" target="_blank" rel="noreferrer">NumPy-Discussion@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/numpy-discussion</a><br>
</blockquote></div>