NumPy ndarray.__irshift__() | Shift NumPy Array Elements to Right
Last Updated :
05 Feb, 2024
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 ])
print (gfg.__irshift__( 2 ))
|
Syntax
Syntax: ndarray.__irshift__($self, value, /)
Parameter
- self: The numpy array.
- value: The number of positions to shift
Return: New array where element is right shifted
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 numpy as np
gfg = np.array([[ 1 , 2 , 3 , 4 , 5 ],
[ 6 , 5 , 4 , 3 , 2 ]])
print (gfg.__irshift__( 1 ))
|
Output
[[0 1 1 2 2]
[3 2 2 1 1]]
Share your thoughts in the comments
Please Login to comment...