median

pydl.median(array, width=None, axis=None, even=False)[source]

Replicate the IDL MEDIAN() function.

Parameters:

array : array-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 is True.

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 input array is not 1 or 2 dimensional.

Notes

  • For arrays with an even number of elements, the numpy.median() function behaves like MEDIAN(array, /EVEN), so the absence of the even keyword has to turn off that behavior.
  • For median filtering, this uses scipy.signal.medfilt() and scipy.signal.medfilt2d() under the hood, but patches up the values on the array boundaries to match the return values of the IDL MEDIAN() function.