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
N
unmasked, non-NaN values, the median isodd
N
:x[(N-1)/2]
even
N
:(x[N/2-1] + x[N/2]) / 2
- Parameters:
- 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.median
Compute the median without special handling of NaN’s.
Examples
nanmedian
is 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