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


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

numpy.ma.MaskedArray class是ndarray的子​​類,旨在處理缺少數據的數字數組。借助於Numpy MaskedArray .__ mul__,我們可以乘以MaskedArray.__mul__()方法中作為參數提供的特定值。

用法: numpy.MaskedArray.__mul__

返回:將self乘以另一個,並返回一個新的蒙版數組。


範例1:
在此示例中,我們可以看到數組中的每個元素都與方法MaskedArray.__mul__()中作為參數給出的值相乘。

# import the important module in python  
import numpy as np  
  
# make an array with numpy  
gfg = np.ma.array([1, 2, 3, 4, 5])  
  
# applying MaskedArray.__mul__() method  
print(gfg.__mul__(5)) 
輸出:
[ 5 10 15 20 25]


範例2:

# import the important module in python  
import numpy as np  
  
# make an array with numpy  
gfg = np.ma.array([[1, 2, 3, 4, 5],  
                [6, 5, 4, 3, 2]])  
  
# applying MaskedArray.__mul__() method  
print(gfg.__mul__(5)) 
輸出:
[[ 5 10 15 20 25]
 [30 25 20 15 10]]


相關用法


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