Count the number of masked elements along the given axis.
An array with (possibly) masked elements.
Axis along which to count. If None (default), a flattened version of the array is used.
The total number of masked elements (axis=None) or the number of masked elements along each slice of the given axis.
See also
MaskedArray.countCount non-masked elements.
>>> import numpy as np
>>> a = np.arange(9).reshape((3,3))
>>> a = np.ma.array(a)
>>> a[1, 0] = np.ma.masked
>>> a[1, 2] = np.ma.masked
>>> a[2, 1] = np.ma.masked
>>> a
masked_array(
data=[[0, 1, 2],
[--, 4, --],
[6, --, 8]],
mask=[[False, False, False],
[ True, False, True],
[False, True, False]],
fill_value=999999)
>>> np.ma.count_masked(a)
3
When the axis keyword is used an array is returned.
>>> np.ma.count_masked(a, axis=0) array([1, 1, 1]) >>> np.ma.count_masked(a, axis=1) array([0, 2, 1])
© 2005–2024 NumPy Developers
Licensed under the 3-clause BSD License.
https://numpy.org/doc/2.4/reference/generated/numpy.ma.count_masked.html