MCPcopy Create free account
hub / github.com/numpy/numpy / reduce

Method reduce

numpy/ma/core.py:6754–6784  ·  view source on GitHub ↗

Reduce target along the given axis.

(self, target, axis=np._NoValue)

Source from the content-addressed store, hash-verified

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."

Callers 15

_block_info_recursionFunction · 0.45
_wrapreductionFunction · 0.45
tensordotFunction · 0.45
test_reduceMethod · 0.45
test_object_logicalMethod · 0.45
test_scalar_reductionMethod · 0.45

Calls 4

getmaskFunction · 0.85
warnMethod · 0.80
viewMethod · 0.45
filledMethod · 0.45