當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python Numpy MaskedArray.__mod__用法及代碼示例

numpy.ma.MaskedArray class是ndarray的子​​類,旨在處理缺少數據的數字數組。在Numpy MaskedArray .__ mod__的幫助下,掩碼數組中的每個元素都在二進製運算符上操作,即mod(%)。請記住,我們可以在數組中使用任何類型的值,並且mod的值將作為MaskedArray.__mod__()中的參數應用。

用法: numpy.MaskedArray.__mod__

返回:返回self%value。


範例1:
我們可以看到通過MaskedArray.__mod__()方法傳遞的值用於對數組的每個元素執行mod操作。

# import the important module in python  
import numpy as np  
      
# make an array with numpy  
gfg = np.ma.array([1, 2.5, 3, 4.8, 5])  
      
# applying MaskedArray.__mod__() method  
print(gfg.__mod__(2)) 
輸出:
[1.0 0.5 1.0 0.7999999999999998 1.0]


範例2:

# import the important module in python  
import numpy as np  
      
# make an array with numpy  
gfg = np.ma.array([[1, 2, 3, 4.45, 5],  
                [6, 5.5, 4, 3, 2.62]])  
      
# applying MaskedArray.__mod__() method  
print(gfg.__mod__(3)) 
輸出:
[[1.0 2.0 0.0 1.4500000000000002 2.0]
 [0.0 2.5 1.0 0.0 2.62]]


相關用法


注:本文由純淨天空篩選整理自Shivam_k大神的英文原創作品 Python | Numpy MaskedArray.__mod__。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。