Skip to main content
`Ctrl`+`K`

# add_array

astropy.nddata.utils.add_array(array_large, array_small, position, *, limit_rounding_method=<ufunc 'ceil'>)

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

  Parameters:
    array_large `ndarray`

      Large array.

    array_small `ndarray`

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

    position `python: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.

    limit_rounding_method `python:callable()`

      The rounding method when calculating the minimum and maximum pixel indices. This must be a callable function. Examples: `ceil`, `floor`, `round`. Default is `ceil`.

  Returns:
    new_array `ndarray`

      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.]])