prtools.pad#

pad(a, shape, fill=0)[source]#

Zero-pad an array.

Note that pad works accepts both two and three dimensional arrays.

Parameters:
  • a (array_like) – Array to be padded.

  • shape (array_like of ints) – Shape of output array in (nrows, ncols).

  • fill (scalar) – Fill vlue used when pad operation increases array size.

Returns:

padded_array – Zero-padded array with shape (nrows, ncols). If a has a third dimension, the return shape will be (depth, nrows, ncols).

Return type:

ndarray

Examples

>>> circ = prtools.circle(shape=(128, 128), radius=64)
>>> circ_pad = prtools.pad(circ, shape=(200, 200))
>>> fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(5, 2))
>>> ax[0].imshow(circ, cmap='gray')
>>> ax[0].set_title('Original array')
>>> ax[1].imshow(circ_pad, cmap='gray')
>>> ax[1].set_title('Padded array')
../_images/prtools-pad-1.png
>>> circ = prtools.circle(shape=(128, 128), radius=64)
>>> circ_pad = prtools.pad(circ, shape=(110, 110))
>>> fig, ax = plt.subplots(nrows=1, ncols=2, figsize=(5, 2))
>>> ax[0].imshow(circ, cmap='gray')
>>> ax[0].set_title('Original array')
>>> ax[1].imshow(circ_pad, cmap='gray')
>>> ax[1].set_title('Padded array')
../_images/prtools-pad-2.png