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 is

  • odd 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:

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