<div dir="ltr"><div>It's definitely just "slicing", but it's a bit inconvenient.  I'm thinking more like:</div><div><br></div><div>arr = np.random.rand(10, 10, 10)</div><div>W = [[3, 2], [4, 6]]  # or W = 4, or W = [4, 5]<br></div><div>arr_padded = np.pad(arr, pad_width=W)</div><div>< Do some stuff to arr_padded ></div><div>arr = np.unpad(arr_padded, pad_width=W)  # Using W just works, no matter how odd the various pad widths were</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 4:29 PM Stephan Hoyer <<a href="mailto:shoyer@gmail.com">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">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 by [(20, 0)].<div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, Apr 12, 2021 at 1:15 PM Jeff Gostick <<a href="mailto:jgostick@gmail.com" target="_blank">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">



















<p style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif">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.<span>  </span>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 padding of [20, 4]).<span> 
</span>This seems like a pretty obvious feature to me so maybe I've just missed
something, but I have looked through all the open and closed issues on github
and don't see anything related to this. <br></p><p style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif"><br></p><p style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif">Jeff G<br></p><p style="margin:0cm;font-size:11pt;font-family:Calibri,sans-serif"><span></span></p>





</div>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@python.org" target="_blank">NumPy-Discussion@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="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">NumPy-Discussion@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/numpy-discussion</a><br>
</blockquote></div>