add_array

astropy.nddata.add_array(array_large, array_small, position)[source]

Add a smaller array at a given position in a larger array.

Parameters:
array_largendarray

Large array.

array_smallndarray

Small array to add. Can be equal to array_large in size in a given dimension, but not larger.

positionpython: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:
new_arrayndarray

The new array formed from the sum of array_large and array_small.

Notes

The addition is done in-place.

Examples

We consider a large array of zeros with the shape 5x5 and a small array of ones with a shape of 3x3:

>>> import numpy as np
>>> from astropy.nddata.utils import add_array
>>> large_array = np.zeros((5, 5))
>>> small_array = np.ones((3, 3))
>>> add_array(large_array, small_array, (1, 2))  
array([[0., 1., 1., 1., 0.],
       [0., 1., 1., 1., 0.],
       [0., 1., 1., 1., 0.],
       [0., 0., 0., 0., 0.],
       [0., 0., 0., 0., 0.]])