numpy.ma.MaskedArray.count()函數計算沿給定軸的數組的非掩碼元素。
用法: numpy.ma.MaskedArray.count(self, axis=None, keepdims = no value)
參數:
axis:[無或整數或整數元組,可選]沿其進行計數的軸。默認軸為“無”,對輸入數組的所有維度執行計數。軸可能為負,在這種情況下,它從最後一個軸開始計數。
keepdims:[布爾,可選]如果將其設置為True,則縮小的軸將保留為尺寸為1的尺寸。使用此選項,結果將針對陣列正確廣播。
Return :[ndarray或scalar]與輸入數組具有相同形狀的數組,但移除了指定的軸。如果數組是0維數組,或者軸為None,則返回標量。
代碼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
相關用法
- Python Wand function()用法及代碼示例
- Python map()用法及代碼示例
- Python hex()用法及代碼示例
- Python dir()用法及代碼示例
- Python sum()用法及代碼示例
- Python ord()用法及代碼示例
- Python id()用法及代碼示例
- Python now()用法及代碼示例
- Python cmp()用法及代碼示例
- Python int()用法及代碼示例
- Python tell()用法及代碼示例
- Python str()用法及代碼示例
- Python oct()用法及代碼示例
- Python property()用法及代碼示例
- Python Wand fx()用法及代碼示例
- Python math.cos()用法及代碼示例
注:本文由純淨天空篩選整理自sanjoy_62大神的英文原創作品 numpy.ma.MaskedArray.count() function – Python。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。