Python| Numpy MaskedArray.__rsub__
numpy.ma.MaskedArray class
是 ndarray 的子类,旨在处理缺失数据的数值数组。在 Numpy MaskedArray.__rsub__的帮助下,我们可以减去在 MaskedArray.__rsub__() 方法中作为参数提供的特定值。将从 numpy 数组中的每个元素中减去值。
Syntax: numpy.MaskedArray.__rsub__
Return: Subtract self from other, and return a new masked array.
示例 #1:
在此示例中,我们可以看到数组中的每个元素都减去了作为 MaskedArray.__rsub__() 方法中的参数给出的值。请记住一件事,它不适用于双精度类型值。
# import the important module in python
import numpy as np
# make an array with numpy
gfg = np.ma.array([11, 22, 23, 24, 25])
# applying MaskedArray.__rsub__() method
print(gfg.__rsub__(5))
输出:
[ -6 -17 -18 -19 -20]
示例 #2:
# import the important module in python
import numpy as np
# make an array with numpy
gfg = np.ma.array([[21, 22, 23, 24, 25],
[26, 25, 24, 23, 22]])
# applying MaskedArray.__rsub__() method
print(gfg.__rsub__(5))
输出:
[[-16 -17 -18 -19 -20]
[-21 -20 -19 -18 -17]]