原文:https://docs.scipy.org/doc/numpy/reference/generated/numpy.ma.count_masked.html
校对:(虚位以待)
numpy.ma.
count_masked
(arr, axis=None)[source]计算沿给定轴的蒙版元素的数量。
参数: | arr:array_like
axis:int,可选
|
---|---|
返回: | count:int,ndarray
|
也可以看看
MaskedArray.count
例子
>>> 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
当使用axis关键字时,返回一个数组。
>>> ma.count_masked(a, axis=0)
array([1, 1, 1])
>>> ma.count_masked(a, axis=1)
array([0, 2, 1])