[Numpy-discussion] rebin

Russell E. Owen owen at astro.washington.edu
Fri Aug 27 17:38:31 CDT 2004


Any suggestions on an efficient means to bin a 2-d array? REBIN is the IDL
function I'm trying to mimic. Binning allows one to combine sets of pixels from
one array to form a new array that is smaller by a given factor along each
dimension.

To nxm bin a 2-dimensional array, one averages (or sums or ?) each nxm block of
entries from the input image to form the corresponding entry of the output
image.

For example, to 2x2 bin a two-dimensional image, one would:
average (0,0), (0,1), (1,0), (1,1) to form (0,0)
average (0,2), (0,3), (1,2), (1,3) to form (0,1)
...

In case it helps, in my immediate case I'm binning a boolean array (a mask) and
thus can live with almost any kind of combination.

-- Russell




More information about the Numpy-discussion mailing list