📜  numpy.ma.MaskedArray.count()函数– Python

📅  最后修改于: 2022-05-13 01:55:26.817000             🧑  作者: Mango

numpy.ma.MaskedArray.count()函数– Python

numpy.ma.MaskedArray.count()函数沿给定轴计算数组的非屏蔽元素。

代码#1:

# Python program explaining
# numpy.ma.MaskedArray.count() function
    
# importing numpy as geek   
# and numpy.ma module as ma  
import numpy as geek  
import numpy.ma as ma
   
arr = ma.arange(6).reshape((2, 3))
arr[1, :] = ma.masked
  
gfg = arr.count(axis = 0)
  
print (gfg)

输出 :

[1 1 1]


代码#2:

# Python program explaining
# numpy.ma.MaskedArray.count() function
    
# importing numpy as geek   
# and numpy.ma module as ma  
import numpy as geek  
import numpy.ma as ma
   
arr = ma.arange(6).reshape((2, 3))
arr[1, :] = ma.masked
  
gfg = arr.count()
  
print (gfg)

输出 :

3