Python| Numpy MaskedArray.__truediv__
numpy.ma.MaskedArray class
是 ndarray 的子类,旨在操作缺失数据的数值数组。在 Numpy MaskedArray.__truediv__的帮助下,我们可以划分在 MaskedArray.__truediv__() 方法中作为参数提供的特定值。
Syntax: numpy.MaskedArray.__truediv__
Return: Divide other into self, and return a new masked array.
示例 #1:
在这个例子中,我们可以看到数组中的每个元素都被作为 MaskedArray.__truediv__() 方法中的参数给出的值划分。
# import the important module in python
import numpy as np
# make an array with numpy
gfg = np.ma.array([22, 33.7, 44.5, 55, 77])
# applying MaskedArray.__truediv__() method
print(gfg.__truediv__(11))
输出:
[2.0 3.063636363636364 4.045454545454546 5.0 7.0]
示例 #2:
# import the important module in python
import numpy as np
# make an array with numpy
gfg = np.ma.array([[10, 20, 30, 40, 50],
[11, 22, 33, 44, 55]])
# applying MaskedArray.__truediv__() method
print(gfg.__truediv__(5))
输出:
[[2.0 4.0 6.0 8.0 10.0]
[2.2 4.4 6.6 8.8 11.0]]