Python| Numpy MaskedArray.__and__
numpy.ma.MaskedArray class
是 ndarray 的子类,旨在处理缺失数据的数值数组。在 Numpy MaskedArray.__and__方法的帮助下,我们可以获得与作为参数提供的值进行与运算的元素。
Syntax: numpy.MaskedArray.__and__
Return: Return self&value.
示例 #1:
在此示例中,我们可以看到每个元素都由作为参数传递的值进行与运算。
# 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.__and__() method
print(gfg.__and__(2))
输出:
[0 2 2 0 0]
示例 #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.__and__() method
print(gfg.__and__(1))
输出:
[[1 0 1 0 1]
[0 1 0 1 0]]