📜  Python| Numpy MaskedArray.__ilshift__()(1)

📅  最后修改于: 2023-12-03 15:04:20.401000             🧑  作者: Mango

Python | Numpy MaskedArray.ilshift()

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.

Syntax
numpy.ma.MaskedArray.__ilshift__(self, other)
Parameters
  • self: This is the masked array object that you want to shift the elements of.
  • other: This is the number of positions that you want to shift the elements of the masked array object by.
Return Value

This method returns the value of the masked array after performing the bit-wise left shift.

Example
>>> 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.

Conclusion

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.