MCPcopy Index your code
hub / github.com/numpy/numpy / _mean

Function _mean

numpy/_core/_methods.py:115–146  ·  view source on GitHub ↗
(a, axis=None, dtype=None, out=None, keepdims=False, *, where=True)

Source from the content-addressed store, hash-verified

113 return um.clip(a, min, max, out=out, **kwargs)
114
115def _mean(a, axis=None, dtype=None, out=None, keepdims=False, *, where=True):
116 arr = asanyarray(a)
117
118 is_float16_result = False
119
120 rcount = _count_reduce_items(arr, axis, keepdims=keepdims, where=where)
121 if rcount == 0 if where is True else umr_any(rcount == 0, axis=None):
122 warnings.warn("Mean of empty slice", RuntimeWarning, stacklevel=2)
123
124 # Cast bool, unsigned int, and int to float64 by default
125 if dtype is None:
126 if issubclass(arr.dtype.type, (nt.integer, nt.bool)):
127 dtype = mu.dtype('f8')
128 elif issubclass(arr.dtype.type, nt.float16):
129 dtype = mu.dtype('f4')
130 is_float16_result = True
131
132 ret = umr_sum(arr, axis, dtype, out, keepdims, where=where)
133 if isinstance(ret, mu.ndarray):
134 ret = um.true_divide(
135 ret, rcount, out=ret, casting='unsafe', subok=False)
136 if is_float16_result and out is None:
137 ret = arr.dtype.type(ret)
138 elif hasattr(ret, 'dtype'):
139 if is_float16_result:
140 ret = arr.dtype.type(ret / rcount)
141 else:
142 ret = ret.dtype.type(ret / rcount)
143 else:
144 ret = ret / rcount
145
146 return ret
147
148def _var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False, *,
149 where=True, mean=None):

Callers

nothing calls this directly

Calls 3

asanyarrayFunction · 0.85
_count_reduce_itemsFunction · 0.85
dtypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…