astropy:docs

extract_array

astropy.nddata.utils.extract_array(array_large, shape, position)[source] [edit on github]

Extract smaller array of given shape and position out of a larger array.

Parameters:

array_large : ndarray

Array to extract another array from.

shape : tuple

Shape of the extracted array.

position : tuple

Position of the small array’s center, with respect to the large array. Coordinates should be in the same order as the array shape.

Returns:

array_small : ndarray

The extracted array

Examples

We consider a large array with the shape 11x10, from which we extract a small array of shape 3x5:

>>> import numpy as np
>>> from astropy.nddata.utils import extract_array
>>> large_array = np.arange(110).reshape((11, 10))
>>> large_array[4:9, 4:9] = np.ones((5, 5))
>>> extract_array(large_array, (3, 5), (7, 7))
array([[ 1,  1,  1,  1, 69],
       [ 1,  1,  1,  1, 79],
       [ 1,  1,  1,  1, 89]])

Page Contents