How to Shift Elements of NumPy Array to the left
To shift the elements of the NumPy Array to the left we use ndarray.__ilshift__() method of the NumPy library in Python.
Let’s understand it better with an example:
Example:
Python3
# import the important module in python import numpy as np # make an array with numpy gfg = np.array([[ 1 , 2 , 3 , 4 , 5 ], [ 6 , 5 , 4 , 3 , 2 ]]) # applying ndarray.__ilshift__() method print (gfg.__ilshift__( 1 )) |
Output
[[ 2 4 6 8 10] [12 10 8 6 4]]
NumPy ndarray.__ilshift__() | Shift NumPy Array Elements to Left
The ndarray.__ilshift__() method is an in-place left-shift operation. It shifts elements in the array to the left of the number of positions specified.
Example
Python3
import numpy as np gfg = np.array([ 1 , 2 , 3 , 4 , 5 ]) # applying ndarray.__ilshift__() method print (gfg.__ilshift__( 2 )) |
Output
[ 4 8 12 16 20]