How to Shift Elements of the NumPy Array to the Right
To shift the elements of the NumPy array to the right we use ndarray.__irshift__() method of the NumPy library in Python.
Let us 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.__irshift__() method print (gfg.__irshift__( 1 )) |
Output
[[0 1 1 2 2] [3 2 2 1 1]]
NumPy ndarray.__irshift__() | Shift NumPy Array Elements to Right
The ndarray.__irshift__() method returns a new array where each element is right-shifted by the value that is passed as a parameter.
Example
Python3
import numpy as np gfg = np.array([ 1 , 2 , 3 , 4 , 5 ]) # applying ndarray.__irshift__() method print (gfg.__irshift__( 2 )) |
Output
[0 0 0 1 1]
Contact Us