- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Shift the bits of an integer to the left and set the count of shifts as an array in Numpy

To shift the bits of an integer to the left, use the **numpy.left_shift()** method in Python Numpy. We have set the count of shifts as a new array.

Bits are shifted to the left by appending x2 0s at the right of x1. Since the internal representation of numbers is in binary format, this operation is equivalent to multiplying x1 by 2**x2. The x1 is the Input values. The x2 is the number of zeros to append to x1. Has to be non-negative. If x1.shape != x2.shape, they must be broadcastable to a common shape (which becomes the shape of the output).

The function left_shift() returns x1 with bits shifted x2 times to the left. This is a scalar if both x1 and x2 are scalars.

## Steps

At first, import the required library −

import numpy as np

Create a One-Dimensional array −

arrLeft = np.array([2, 3, 5])

Displaying our array −

print("Array...

",arr)

Get the datatype −

print("

Array datatype...

",arr.dtype)

Get the dimensions of the Array −

print("

Array Dimensions...

",arr.ndim)

Get the shape of the Array −

print("

Our Array Shape...

",arr.shape)

Get the number of elements of the Array −

print("

Elements in the Array...

",arr.size)

The actual integer value −

val = 25

To shift the bits of an integer to the left, use the numpy.left_shift() method. We have set the count of shifts as an array arrLeft −

print("

Result (left shift)...

",np.left_shift(val, arrLeft))

## Example

import numpy as np # Create a One-Dimensional array arrLeft = np.array([2, 3, 5]) # Displaying our array print("Array...

",arrLeft) # Get the datatype print("

Array datatype...

",arrLeft.dtype) # Get the dimensions of the Array print("

Array Dimensions...

",arrLeft.ndim) # Get the shape of the Array print("

Our Array Shape...

",arrLeft.shape) # Get the number of elements of the Array print("

Elements in the Array...

",arrLeft.size) # The actual integer value val = 25 # To shift the bits of an integer to the left, use the numpy.left_shift() method in Python Numpy # We have set the count of shifts as an array arrLeft print("

Result (left shift)...

",np.left_shift(val, arrLeft))

## Output

Array... [2 3 5] Array datatype... int64 Array Dimensions... 1 Our Array Shape... (3,) Elements in the Array... 3 Result (left shift)... [100 200 800]

- Related Articles
- Shift the bits of an integer to the right and set the count of shifts as an array with signed integer type in Numpy
- Shift the bits of an integer to the left in Numpy
- Shift the bits of integer array elements to the left in Numpy
- Shift the bits of an integer to the right in Numpy
- Shift the bits of integer array elements to the right in Numpy
- Shift the bits of array elements of a Two-Dimensional array to the left in Numpy
- Golang Program to count the set bits in an integer.
- C/C++ Program to the Count set bits in an integer?
- Count set bits in an integer in C++
- Python Program to Count set bits in an integer
- Java Program to Count set bits in an integer
- C/C++ Program to Count set bits in an integer?
- Shift the bits of array elements of a Two-Dimensional array to the right in Numpy
- Sort an array according to count of set bits in C++
- Left-justify elements of an array and set the characters to use for padding in Numpy