MCPcopy
hub / github.com/numpy/numpy / mean

Method mean

numpy/ma/core.py:5376–5430  ·  view source on GitHub ↗

Returns the average of the array elements along given axis. Masked entries are ignored, and result elements which are not finite will be masked. Refer to `numpy.mean` for full documentation. See Also -------- numpy.ndarray.mean : correspond

(self, axis=None, dtype=None, out=None, keepdims=np._NoValue)

Source from the content-addressed store, hash-verified

5374 return result
5375
5376 def mean(self, axis=None, dtype=None, out=None, keepdims=np._NoValue):
5377 """
5378 Returns the average of the array elements along given axis.
5379
5380 Masked entries are ignored, and result elements which are not
5381 finite will be masked.
5382
5383 Refer to `numpy.mean` for full documentation.
5384
5385 See Also
5386 --------
5387 numpy.ndarray.mean : corresponding function for ndarrays
5388 numpy.mean : Equivalent function
5389 numpy.ma.average : Weighted average.
5390
5391 Examples
5392 --------
5393 >>> import numpy as np
5394 >>> a = np.ma.array([1,2,3], mask=[False, False, True])
5395 >>> a
5396 masked_array(data=[1, 2, --],
5397 mask=[False, False, True],
5398 fill_value=999999)
5399 >>> a.mean()
5400 1.5
5401
5402 """
5403 kwargs = {} if keepdims is np._NoValue else {'keepdims': keepdims}
5404 if self._mask is nomask:
5405 result = super().mean(axis=axis, dtype=dtype, **kwargs)[()]
5406 else:
5407 is_float16_result = False
5408 if dtype is None:
5409 if issubclass(self.dtype.type, (ntypes.integer, ntypes.bool)):
5410 dtype = mu.dtype('f8')
5411 elif issubclass(self.dtype.type, ntypes.float16):
5412 dtype = mu.dtype('f4')
5413 is_float16_result = True
5414 dsum = self.sum(axis=axis, dtype=dtype, **kwargs)
5415 cnt = self.count(axis=axis, **kwargs)
5416 if cnt.shape == () and (cnt == 0):
5417 result = masked
5418 elif is_float16_result:
5419 result = self.dtype.type(dsum * 1. / cnt)
5420 else:
5421 result = dsum * 1. / cnt
5422 if out is not None:
5423 out.flat = result
5424 if isinstance(out, MaskedArray):
5425 outmask = getmask(out)
5426 if outmask is nomask:
5427 outmask = out._mask = make_mask_none(out.shape)
5428 outmask.flat = getmask(result)
5429 return out
5430 return result
5431
5432 def anom(self, axis=None, dtype=None):
5433 """

Callers 15

anomMethod · 0.95
varMethod · 0.95
performance.pyFile · 0.45
test_typical_casesMethod · 0.45
test_attributesMethod · 0.45
_meanFunction · 0.45
test_python_typeMethod · 0.45

Calls 5

sumMethod · 0.95
countMethod · 0.95
getmaskFunction · 0.85
make_mask_noneFunction · 0.85
dtypeMethod · 0.45

Tested by 15

test_typical_casesMethod · 0.36
test_attributesMethod · 0.36
_meanFunction · 0.36
test_python_typeMethod · 0.36
test_mean_axis_errorMethod · 0.36
test_mean_whereMethod · 0.36
test_subclassMethod · 0.36