Python| Numpy MaskedArray.__rshift__
numpy.ma.MaskedArray class
是 ndarray 的子类,旨在处理缺失数据的数值数组。在 Numpy MaskedArray.__rshift__方法的帮助下,我们可以获得按作为参数提供的值右移的元素。
Syntax: numpy.MaskedArray.__rshift__
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.__rshift__() method
print(gfg.__rshift__(2))
输出:
[0 0 0 1 1]
示例 #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.__rshift__() method
print(gfg.__rshift__(1))
输出:
[[0 1 1 2 2]
[3 2 2 1 1]]