block_reduce(data, block_size, func=<function sum>)¶
Downsample a data array by applying a function to local blocks.
datais not perfectly divisible by
block_sizealong a given axis then the data will be trimmed (from the end) along that axis.
The data to be resampled.
intor array_like (
The integer block size along each axis. If
block_sizeis a scalar and
datahas more than one dimension, then
block_sizewill be used for for every axis.
The method to use to downsample the data. Must be a callable that takes in a 4D
block_reducegets reshaped as 4D) and has an
axiskeyword that accepts tuples. This function will be called with
axis=(2, 3)and it should return a 2D array. The default is
sum, which provides block summation (and conserves the data sum).
The resampled data.
>>> import numpy as np >>> from astropy.nddata 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]])