numpy 1.22.4 Pypi GitHub Homepage
Other Docs
ParametersReturnsBackRef
count(self, axis=None, keepdims=<no value>)

Parameters

axis : None or int or tuple of ints, optional

Axis or axes along which the count is performed. The default, None, performs the count over all the dimensions of the input array. :None:None:`axis` may be negative, in which case it counts from the last to the first axis.

versionadded

If this is a tuple of ints, the count is performed on multiple axes, instead of a single axis or all the axes as before.

keepdims : bool, optional

If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the array.

Returns

result : ndarray or scalar

An array with the same shape as the input array, with the specified axis removed. If the array is a 0-d array, or if :None:None:`axis` is None, a scalar is returned.

Count the non-masked elements of the array along the given axis.

See Also

ma.count_masked

Count masked elements in array or along a given axis.

Examples

This example is valid syntax, but we were not able to check execution
>>> import numpy.ma as ma
... a = ma.arange(6).reshape((2, 3))
... a[1, :] = ma.masked
... a masked_array( data=[[0, 1, 2], [--, --, --]], mask=[[False, False, False], [ True, True, True]], fill_value=999999)
This example is valid syntax, but we were not able to check execution
>>> a.count()
3

When the :None:None:`axis` keyword is specified an array of appropriate size is returned.

This example is valid syntax, but we were not able to check execution
>>> a.count(axis=0)
array([1, 1, 1])
This example is valid syntax, but we were not able to check execution
>>> a.count(axis=1)
array([3, 0])
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

numpy.ma.extras.count_masked

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /numpy/ma/core.py#4443
type: <class 'function'>
Commit: