# rebin¶

pydl.rebin(x, d, sample=False)[source]

Resize x to new dimensions given by d. The new dimensions must be integer multiples or factors of the original dimensions.

Although there are some elegant solutions out there for rebinning, this function is intended to replace the IDL REBIN() function, which has a number of special properties:

• It refuses to perform extrapolation when rebinning to a larger size in a particular dimension.

• It can simultaneously rebin to a larger size in one dimension while rebinning to a smaller size in another dimension.

Parameters
xndarray

The array to resample.

dtuple()

The new shape of the array.

samplebool, optional

If True, nearest-neighbor techniques will be used instead of interpolation.

Returns
ndarray

The resampled array.

Raises
ValueError

If the new dimensions are incompatible with the algorithm.

References

http://www.harrisgeospatial.com/docs/rebin.html

Examples

>>> from numpy import arange, float
>>> from pydl import rebin
>>> rebin(arange(10, dtype=float), (5,))
array([0.5, 2.5, 4.5, 6.5, 8.5])
>>> rebin(arange(5, dtype=float), (10,))
array([0. , 0.5, 1. , 1.5, 2. , 2.5, 3. , 3.5, 4. , 4. ])