MaskedArray.count()

numpy.ma.MaskedArray.count

MaskedArray.count(axis=None) [source]

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

Parameters:

axis : int, optional

Axis along which to count the non-masked elements. If axis is None, all non-masked elements are counted.

Returns:

result : int or ndarray

If axis is None, an integer count is returned. When axis is not None, an array with shape determined by the lengths of the remaining axes, is returned.

See also

count_masked
Count masked elements in array or along a given axis.

Examples

>>> 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)
>>> a.count()
3

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

>>> a.count(axis=0)
array([1, 1, 1])
>>> a.count(axis=1)
array([3, 0])

© 2008–2016 NumPy Developers
Licensed under the NumPy License.
https://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.ma.MaskedArray.count.html

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部