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)
| 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 | """ |