You are viewing an older version (2.4.3). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.4.3 / numpy / ma / extras / count_masked

function

numpy.ma.extras:count_masked

source: /numpy/ma/extras.py :66

Signature

def   count_masked ( arr axis = None )

Summary

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.

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 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
np.ma.count_masked(a)
When the `axis` keyword is used an array is returned.
np.ma.count_masked(a, axis=0)
np.ma.count_masked(a, axis=1)

See also

MaskedArray.count

Count non-masked elements.

Aliases

  • numpy.ma.count_masked