astropy.nddata.block_reduce(data, block_size, func=<function sum at 0x7f4e427b1e18>)[source]

Downsample a data array by applying a function to local blocks.

If data is not perfectly divisible by block_size along a given axis then the data will be trimmed (from the end) along that axis.

data : array_like

The data to be resampled.

block_size : int or array_like (int)

The integer block size along each axis. If block_size is a scalar and data has more than one dimension, then block_size will be used for for every axis.

func : callable, optional

The method to use to downsample the data. Must be a callable that takes in a ndarray along with an axis keyword, which defines the axis along which the function is applied. The default is sum, which provides block summation (and conserves the data sum).

output : array-like

The resampled data.


>>> import numpy as np
>>> from astropy.nddata.utils import block_reduce
>>> data = np.arange(16).reshape(4, 4)
>>> block_reduce(data, 2)    # doctest: +SKIP
array([[10, 18],
       [42, 50]])
>>> block_reduce(data, 2, func=np.mean)    # doctest: +SKIP
array([[  2.5,   4.5],
       [ 10.5,  12.5]])