- 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 array elements of a Two-Dimensional array to the right in Numpy
To shift the bits of array elements of a 2d array to the right, use the numpy.right_shift() method in Python Numpy. Bits are shifted to the right x2. Because the internal representation of numbers is in binary format, this operation is equivalent to dividing x1 by 2**x2.
The x1 is the Input values. The x2 is the number of bits to remove at the right of x1. If x1.shape != x2.shape, they must be broadcastable to a common shape.
The function right_shift() returns x1 with bits shifted x2 times to the right. This is a scalar if both x1 and x2 are scalars.
Steps
At first, import the required library −
import numpy as np
Create a Two-Dimensional array −
arr = np.array([[56, 87, 23], [92, 81, 98]])
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 count of right right −
valRight = 3
To shift the bits of array elements of a 2d array to the right, use the numpy.right_shift() method −
print("
Result (right shift)...
",np.right_shift(arr, valRight))
Example
import numpy as np # Create a Two-Dimensional array arr = np.array([[56, 87, 23], [92, 81, 98]]) # 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 count of right right valRight = 3 # To shift the bits of an integer to the right, use the numpy.right_shift() method in Python Numpy print("
Result (right shift)...
",np.right_shift(arr, valRight))
Output
Array... [[56 87 23] [92 81 98]] Array datatype... int64 Array Dimensions... 2 Our Array Shape... (2, 3) Elements in the Array... 6 Result (right shift)... [[ 7 10 2] [11 10 12]]
- Related Articles
- Shift the bits of array elements of a Two-Dimensional array to the left in Numpy
- Shift the bits of integer array elements to the right 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
- Pack the elements of a binary-valued Numpy array into bits in a uint8 array
- Java Program to shift array elements to the right
- 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 and set the count of shifts as an array in Numpy
- Pack the elements of a binary-valued Numpy array into bits in a uint8 array over axis 1
- Pack the elements of a binary-valued Numpy array into bits in a uint8 array over negative axis
- Shift the bits of an integer to the left in Numpy
- Pack the elements of a binary-valued array into bits in a uint8 array over specific axis in Numpy
- Compute the bit-wise NOT of a Two-Dimensional array element-wise in Numpy
- Apply the ufunc outer() function to all pairs of Two-Dimensional Array in Numpy
- Return an array with the elements of a Numpy array right-justified in a string of length width
