prtools.subarray#

subarray(a, shape, shift=(0, 0))[source]#

Extract a contiguous subarray from a larger array.

The subarray is extracted about the center of the source array unless a shift is specified.

Parameters:
  • a (array_like) – Source array

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

  • shift (array_like of ints) – Relative shift of the center of the subarray in (row, col).

Returns:

out – Subarray extracted from the source array.

Return type:

ndarray

Examples

>>> circ = prtools.circle(shape=(128,128), radius=64)
>>> circ_subarray = prtools.subarray(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_subarray, cmap='gray')
>>> ax[1].set_title('Subarray')
../_images/prtools-subarray-1.png
>>> circ = prtools.circle(shape=(128,128), radius=64)
>>> circ_subarray = prtools.subarray(circ, shape=(64,64), shift=(32,32))
>>> 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_subarray, cmap='gray')
>>> ax[1].set_title('Subarray')
../_images/prtools-subarray-2.png