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

Function _mean

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

Source from the content-addressed store, hash-verified

99 return um.clip(a, min, max, out=out, **kwargs)
100
101def _mean(a, axis=None, dtype=None, out=None, keepdims=False, *, where=True):
102 arr = asanyarray(a)
103
104 is_float16_result = False
105
106 rcount = _count_reduce_items(arr, axis, keepdims=keepdims, where=where)
107 if rcount == 0 if where is True else umr_any(rcount == 0, axis=None):
108 warnings.warn("Mean of empty slice.", RuntimeWarning, stacklevel=2)
109
110 # Cast bool, unsigned int, and int to float64 by default
111 if dtype is None:
112 if issubclass(arr.dtype.type, (nt.integer, nt.bool_)):
113 dtype = mu.dtype('f8')
114 elif issubclass(arr.dtype.type, nt.float16):
115 dtype = mu.dtype('f4')
116 is_float16_result = True
117
118 ret = umr_sum(arr, axis, dtype, out, keepdims, where=where)
119 if isinstance(ret, mu.ndarray):
120 with _no_nep50_warning():
121 ret = um.true_divide(
122 ret, rcount, out=ret, casting='unsafe', subok=False)
123 if is_float16_result and out is None:
124 ret = arr.dtype.type(ret)
125 elif hasattr(ret, 'dtype'):
126 if is_float16_result:
127 ret = arr.dtype.type(ret / rcount)
128 else:
129 ret = ret.dtype.type(ret / rcount)
130 else:
131 ret = ret / rcount
132
133 return ret
134
135def _var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False, *,
136 where=True):

Callers

nothing calls this directly

Calls 5

_no_nep50_warningFunction · 0.90
asanyarrayFunction · 0.85
_count_reduce_itemsFunction · 0.85
warnMethod · 0.80
dtypeMethod · 0.45

Tested by

no test coverage detected