scipp.nanmedian#
- scipp.nanmedian(x, dim=None)#
Compute the median of the input values ignoring NaN’s.
The median is the middle value of a sorted copy of the input array along each reduced dimension. That is, for an array of
Nunmasked, non-NaN values, the median isodd
N:x[(N-1)/2]even
N:(x[N/2-1] + x[N/2]) / 2
- Parameters:
x (
scipp.typing.VariableLike) – Input data.dim (
Union[str,Iterable[str],None], default:None) – Dimension(s) along which to calculate the median. If not given, the median over a flattened version of the array is calculated.
- Returns:
Same type as x– The median of the input values.- Raises:
scipp.VariancesError – If the input has variances.
scipp.DTypeError – If the input is binned or does otherwise not support computing medians.
ValueError – If the input has masks. Mask out NaN’s and then use
scipp.median()instead.
See also
scipp.medianCompute the median without special handling of NaN’s.
Examples
nanmedianis available as a method:>>> x = sc.array(dims=['x'], values=[2, 5, 1, np.nan, 8, 4]) >>> x.nanmedian() <scipp.Variable> () float64 [dimensionless] 4 >>> x = sc.array(dims=['x'], values=[2, np.nan, 5, 1, 8]) >>> x.nanmedian() <scipp.Variable> () float64 [dimensionless] 3.5