Python Numpy MaskedArray.__mul__

numpy.ma.MaskedArray类是ndarray的一个子类,旨在操作有缺失数据的数字数组。在Numpy MaskedArray.__mul__的帮助下,我们可以对MaskedArray.__mul__()方法中作为参数提供的一个特定值进行乘法运算。

语法: numpy.MaskedArray.__mul__

返回:将自己乘以其他,并返回一个新的屏蔽数组。

例子#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]]

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程