sort + indexing median, faster for small medians along multiple dimensions due to the high overhead of apply_along_axis see nanmedian for parameter usage
(a, axis=None, out=None, overwrite_input=False)
| 1098 | |
| 1099 | |
| 1100 | def _nanmedian_small(a, axis=None, out=None, overwrite_input=False): |
| 1101 | """ |
| 1102 | sort + indexing median, faster for small medians along multiple |
| 1103 | dimensions due to the high overhead of apply_along_axis |
| 1104 | |
| 1105 | see nanmedian for parameter usage |
| 1106 | """ |
| 1107 | a = np.ma.masked_array(a, np.isnan(a)) |
| 1108 | m = np.ma.median(a, axis=axis, overwrite_input=overwrite_input) |
| 1109 | for i in range(np.count_nonzero(m.mask.ravel())): |
| 1110 | warnings.warn("All-NaN slice encountered", RuntimeWarning, |
| 1111 | stacklevel=5) |
| 1112 | |
| 1113 | fill_value = np.timedelta64("NaT") if m.dtype.kind == "m" else np.nan |
| 1114 | if out is not None: |
| 1115 | out[...] = m.filled(fill_value) |
| 1116 | return out |
| 1117 | return m.filled(fill_value) |
| 1118 | |
| 1119 | |
| 1120 | def _nanmedian_dispatcher( |
no test coverage detected
searching dependent graphs…