median¶
- pydl.median(array, width=None, axis=None, even=False)[source]¶
Replicate the IDL
MEDIAN()
function.- Parameters:
- arrayarray-like
Compute the median of this array.
- width
int
, optional Size of the neighborhood in which to compute the median (i.e., perform median filtering). If omitted, the median of the whole array is returned.
- axis
int
, optional Compute the median over this axis for a multi-dimensional array. If ommitted, the median over the entire array will be returned. If set, this function will behave as though
even
isTrue
.- even
bool
, optional If set to
True
, the median of arrays with an even number of elements will be the average of the middle two values.
- Returns:
- array-like
The median of the array.
- Raises:
ValueError
If
width
is set, and the inputarray
is not 1 or 2 dimensional.
Notes
For arrays with an even number of elements, the
numpy.median()
function behaves likeMEDIAN(array, /EVEN)
, so the absence of theeven
keyword has to turn off that behavior.For median filtering, this uses
scipy.signal.medfilt()
andscipy.signal.medfilt2d()
under the hood, but patches up the values on the array boundaries to match the return values of the IDLMEDIAN()
function.
References