Open In App

NumPy ndarray.__ilshift__() | Shift NumPy Array Elements to Left

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

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]

Syntax

Syntax: ndarray.__ilshift__($self, value, /) 

Parameters

  • self: The numpy array.
  • value: The number of positions to shift.

Return: The array with its elements shifted left side

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

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

Similar Reads