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)
| 5304 | return result |
| 5305 | |
| 5306 | def mean(self, axis=None, dtype=None, out=None, keepdims=np._NoValue): |
| 5307 | """ |
| 5308 | Returns the average of the array elements along given axis. |
| 5309 | |
| 5310 | Masked entries are ignored, and result elements which are not |
| 5311 | finite will be masked. |
| 5312 | |
| 5313 | Refer to `numpy.mean` for full documentation. |
| 5314 | |
| 5315 | See Also |
| 5316 | -------- |
| 5317 | numpy.ndarray.mean : corresponding function for ndarrays |
| 5318 | numpy.mean : Equivalent function |
| 5319 | numpy.ma.average : Weighted average. |
| 5320 | |
| 5321 | Examples |
| 5322 | -------- |
| 5323 | >>> a = np.ma.array([1,2,3], mask=[False, False, True]) |
| 5324 | >>> a |
| 5325 | masked_array(data=[1, 2, --], |
| 5326 | mask=[False, False, True], |
| 5327 | fill_value=999999) |
| 5328 | >>> a.mean() |
| 5329 | 1.5 |
| 5330 | |
| 5331 | """ |
| 5332 | kwargs = {} if keepdims is np._NoValue else {'keepdims': keepdims} |
| 5333 | if self._mask is nomask: |
| 5334 | result = super().mean(axis=axis, dtype=dtype, **kwargs)[()] |
| 5335 | else: |
| 5336 | is_float16_result = False |
| 5337 | if dtype is None: |
| 5338 | if issubclass(self.dtype.type, (ntypes.integer, ntypes.bool_)): |
| 5339 | dtype = mu.dtype('f8') |
| 5340 | elif issubclass(self.dtype.type, ntypes.float16): |
| 5341 | dtype = mu.dtype('f4') |
| 5342 | is_float16_result = True |
| 5343 | dsum = self.sum(axis=axis, dtype=dtype, **kwargs) |
| 5344 | cnt = self.count(axis=axis, **kwargs) |
| 5345 | if cnt.shape == () and (cnt == 0): |
| 5346 | result = masked |
| 5347 | elif is_float16_result: |
| 5348 | result = self.dtype.type(dsum * 1. / cnt) |
| 5349 | else: |
| 5350 | result = dsum * 1. / cnt |
| 5351 | if out is not None: |
| 5352 | out.flat = result |
| 5353 | if isinstance(out, MaskedArray): |
| 5354 | outmask = getmask(out) |
| 5355 | if outmask is nomask: |
| 5356 | outmask = out._mask = make_mask_none(out.shape) |
| 5357 | outmask.flat = getmask(result) |
| 5358 | return out |
| 5359 | return result |
| 5360 | |
| 5361 | def anom(self, axis=None, dtype=None): |
| 5362 | """ |