Python| Numpy MaskedArray.__mul__
numpy.ma.MaskedArray class
是 ndarray 的子类,旨在处理缺失数据的数值数组。在 Numpy MaskedArray.__mul__的帮助下,我们可以乘以在 MaskedArray.__mul__() 方法中作为参数提供的特定值。
Syntax: numpy.MaskedArray.__mul__
Return: Multiply self by other, and return a new masked array.
示例 #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]]