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

Function _count_reduce_items

numpy/core/_methods.py:67–88  ·  view source on GitHub ↗
(arr, axis, keepdims=False, where=True)

Source from the content-addressed store, hash-verified

65 return umr_all(a, axis, dtype, out, keepdims, where=where)
66
67def _count_reduce_items(arr, axis, keepdims=False, where=True):
68 # fast-path for the default case
69 if where is True:
70 # no boolean mask given, calculate items according to axis
71 if axis is None:
72 axis = tuple(range(arr.ndim))
73 elif not isinstance(axis, tuple):
74 axis = (axis,)
75 items = 1
76 for ax in axis:
77 items *= arr.shape[mu.normalize_axis_index(ax, arr.ndim)]
78 items = nt.intp(items)
79 else:
80 # TODO: Optimize case when `where` is broadcast along a non-reduction
81 # axis and full sum is more excessive than needed.
82
83 # guarded to protect circular imports
84 from numpy.lib.stride_tricks import broadcast_to
85 # count True values in (potentially broadcasted) boolean mask
86 items = umr_sum(broadcast_to(where, arr.shape), axis, nt.intp, None,
87 keepdims)
88 return items
89
90def _clip(a, min=None, max=None, out=None, **kwargs):
91 if min is None and max is None:

Callers 2

_meanFunction · 0.85
_varFunction · 0.85

Calls 1

broadcast_toFunction · 0.90

Tested by

no test coverage detected