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.
Parameters: | data : array_like
block_size : int or array_like (int)
func : callable, optional
|
---|---|
Returns: | output : array-like
|
Examples
>>> import numpy as np
>>> from astropy.nddata.utils import block_reduce
>>> data = np.arange(16).reshape(4, 4)
>>> block_reduce(data, 2)
array([[10, 18],
[42, 50]])
>>> block_reduce(data, 2, func=np.mean)
array([[ 2.5, 4.5],
[ 10.5, 12.5]])