📅  最后修改于: 2023-12-03 15:04:20.401000             🧑  作者: Mango
The MaskedArray.__ilshift__()
method is a NumPy function that allows you to perform <<=
bitwise left shift on the elements of the array, and returns the value of the array after performing the shift operation. This method only works with 'int' and 'long' type arrays, and cannot be used with 'float' or 'complex' type arrays.
numpy.ma.MaskedArray.__ilshift__(self, other)
This method returns the value of the masked array after performing the bit-wise left shift.
>>> import numpy as np
>>> arr = np.ma.array([33, 21, 39], mask=[False, True, False])
>>> arr <<= 2
>>> print(arr)
masked_array(data=[132, --, 156],
mask=[False, True, False],
fill_value=999999)
Here, we have created a masked array and performed bitwise left shift on it by 2 positions. The output shows the resulting array with the shifted values, and the mask indicating the missing value that was masked earlier.
In this article, we have learned how to use the MaskedArray.__ilshift__()
method in NumPy to perform bitwise left shift on the elements of a masked array object. This method is particularly useful when you want to shift binary values to the left for various bitwise operations.