numpy.ma.MaskedArray类是ndarray的一个子类,旨在操作有缺失数据的数字数组。在Numpy MaskedArray.__iadd__
的帮助下,我们可以在MaskedArray.__iadd__()
方法中添加一个作为参数提供的特定值。值将被添加到numpy数组中的每一个元素。
语法: numpy.MaskedArray.__iadd__(other)
返回:在原地将其他加入自己。
例子#1 :
在这个例子中,我们可以看到数组中的每一个元素都被加上了MaskedArray.__iadd__()
方法中作为参数的值。记住一件事,它对双倍类型的值不起作用。
# import the important module in python
import numpy as np
# make an array with numpy
gfg = np.ma.array([1, 2, 3, 4.7, 5.2])
# applying MaskedArray.__iadd__() method
print(gfg.__iadd__(5))
输出:
[ 6. 7. 8. 9.7 10.2]
示例 #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.__iadd__() method
print(gfg.__iadd__(5))
输出:
[[ 6 7 8 9 10]
[11 10 9 8 7]]