Generic class for maximum/minimum functions. .. note:: This is the base class for `_maximum_operation` and `_minimum_operation`.
| 6733 | |
| 6734 | |
| 6735 | class _extrema_operation(_MaskedUFunc): |
| 6736 | """ |
| 6737 | Generic class for maximum/minimum functions. |
| 6738 | |
| 6739 | .. note:: |
| 6740 | This is the base class for `_maximum_operation` and |
| 6741 | `_minimum_operation`. |
| 6742 | |
| 6743 | """ |
| 6744 | def __init__(self, ufunc, compare, fill_value): |
| 6745 | super().__init__(ufunc) |
| 6746 | self.compare = compare |
| 6747 | self.fill_value_func = fill_value |
| 6748 | |
| 6749 | def __call__(self, a, b): |
| 6750 | "Executes the call behavior." |
| 6751 | |
| 6752 | return where(self.compare(a, b), a, b) |
| 6753 | |
| 6754 | def reduce(self, target, axis=np._NoValue): |
| 6755 | "Reduce target along the given axis." |
| 6756 | target = narray(target, copy=False, subok=True) |
| 6757 | m = getmask(target) |
| 6758 | |
| 6759 | if axis is np._NoValue and target.ndim > 1: |
| 6760 | # 2017-05-06, Numpy 1.13.0: warn on axis default |
| 6761 | warnings.warn( |
| 6762 | f"In the future the default for ma.{self.__name__}.reduce will be axis=0, " |
| 6763 | f"not the current None, to match np.{self.__name__}.reduce. " |
| 6764 | "Explicitly pass 0 or None to silence this warning.", |
| 6765 | MaskedArrayFutureWarning, stacklevel=2) |
| 6766 | axis = None |
| 6767 | |
| 6768 | if axis is not np._NoValue: |
| 6769 | kwargs = dict(axis=axis) |
| 6770 | else: |
| 6771 | kwargs = dict() |
| 6772 | |
| 6773 | if m is nomask: |
| 6774 | t = self.f.reduce(target, **kwargs) |
| 6775 | else: |
| 6776 | target = target.filled( |
| 6777 | self.fill_value_func(target)).view(type(target)) |
| 6778 | t = self.f.reduce(target, **kwargs) |
| 6779 | m = umath.logical_and.reduce(m, **kwargs) |
| 6780 | if hasattr(t, '_mask'): |
| 6781 | t._mask = m |
| 6782 | elif m: |
| 6783 | t = masked |
| 6784 | return t |
| 6785 | |
| 6786 | def outer(self, a, b): |
| 6787 | "Return the function applied to the outer product of a and b." |
| 6788 | ma = getmask(a) |
| 6789 | mb = getmask(b) |
| 6790 | if ma is nomask and mb is nomask: |
| 6791 | m = nomask |
| 6792 | else: |