diff options
Diffstat (limited to 'numpy/ma/extras.py')
-rw-r--r-- | numpy/ma/extras.py | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py index 1aa43a222..4454781c3 100644 --- a/numpy/ma/extras.py +++ b/numpy/ma/extras.py @@ -56,11 +56,48 @@ def count_masked(arr, axis=None): """ Count the number of masked elements along the given axis. + Parameters ---------- + arr : array_like + An array with (possibly) masked elements. axis : int, optional - Axis along which to count. - If None (default), a flattened version of the array is used. + Axis along which to count. If None (default), a flattened + version of the array is used. + + Returns + ------- + count : int, ndarray + The total number of masked elements (axis=None) or the number + of masked elements along each slice of the given axis. + + Examples + -------- + >>> import numpy.ma as ma + >>> a = np.arange(9).reshape((3,3)) + >>> a = ma.array(a) + >>> a[1, 0] = ma.masked + >>> a[1, 2] = ma.masked + >>> a[2, 1] = 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) + >>> ma.count_masked(a) + 3 + + When the `axis` keyword is used an array is returned. + + >>> ma.count_masked(a, axis=0) + array([1, 1, 1]) + >>> ma.count_masked(a, axis=1) + array([0, 2, 1]) """ m = getmaskarray(arr) |