skmap.misc.nan_percentile#

nan_percentile(arr, q=[25, 50, 75], keep_original_vals=False)[source]#

Optimized function to calculate percentiles ignoring np.nan in a 3D Numpy array [1].

Parameters:
  • arr (ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]) – 3D Numpy array where the first dimension is used to derive the percentiles.

  • q (List) – Percentiles values between 0 and 100.

  • keep_original_vals (bool) – If True it does a copy of arr to preserve the structure and values.

Return type:

ndarray[tuple[Any, ...], dtype[TypeVar(_ScalarT, bound= generic)]]

References

[1] Kersten’s blog

Examples

>>> import numpy as np
>>> from skmap.misc import nan_percentile
>>>
>>> data = np.random.rand(10, 10, 10)
>>> data[2:5,0:10,0] = np.nan
>>> data_perc = nan_percentile(data, q=[25, 50, 75])
>>> print(f'Shape: data={data.shape} data_perc={data_perc.shape}')
Shape: data=(10, 10, 10) data_perc=(3, 10, 10)