# cf.Data.median¶

Data.median(axes=None, squeeze=False, mtol=1, inplace=False)[source]

Calculate median values.

Calculates the median value or the median values along axes.

See https://ncas-cms.github.io/cf-python/analysis.html#collapse-methods for mathematical definitions.

Parameters
axes: (sequence of) int, optional

The axes to be collapsed. By default all axes are collapsed, resulting in output with size 1. Each axis is identified by its integer position. If axes is an empty sequence then the collapse is applied to each scalar element and the result has the same shape as the input data.

squeeze: bool, optional

By default, the axes which are collapsed are left in the result as dimensions with size one, so that the result will broadcast correctly against the input array. If set to True then collapsed axes are removed from the data.

mtol: number, optional

The sample size threshold below which collapsed values are set to missing data. It is defined as a fraction (between 0 and 1 inclusive) of the contributing input data values.

The default of mtol is 1, meaning that a missing datum in the output array occurs whenever all of its contributing input array elements are missing data.

For other values, a missing datum in the output array occurs whenever more than 100*mtol% of its contributing input array elements are missing data.

Note that for non-zero values of mtol, different collapsed elements may have different sample sizes, depending on the distribution of missing data in the input data.

inplace: bool, optional

If True then do the operation in-place and return None.

Returns
Data or None

The collapsed data, or None if the operation was in-place.

Examples

>>> a = np.ma.arange(12).reshape(4, 3)
>>> d = cf.Data(a, 'K')