Open In App

NumPy ndarray.__irshift__() | Shift NumPy Array Elements to Right

Last Updated : 05 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

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]

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 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]]

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads