[Numpy-discussion] rebin

Russell E. Owen owen at astro.washington.edu
Fri Aug 27 17:38:31 EDT 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

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

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