

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 right in Numpy
<p>To shift the bits of an integer to the right, use the <strong>numpy.right_shift()</strong> 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.</p><p>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.</p><p>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.</p><h2>Steps</h2><p>At first, import the required library −</p><pre class="result notranslate">import numpy as np</pre><p>Create a 0d array −</p><pre class="result notranslate">arr = np.array(65) </pre><p>Displaying our array −</p><pre class="result notranslate">print("Array... ",arr)</pre><p>Get the datatype −</p><pre class="result notranslate">print(" Array datatype... ",arr.dtype) </pre><p>Get the dimensions of the Array −</p><pre class="result notranslate">print(" Array Dimensions... ",arr.ndim)</pre><p>Get the shape of the Array −</p><pre class="result notranslate">print(" Our Array Shape... ",arr.shape) </pre><p>Get the number of elements of the Array −</p><pre class="result notranslate">print(" Elements in the Array... ",arr.size)</pre><p>The count of right shift −</p><pre class="result notranslate">valRight = 2 </pre><p>To shift the bits of an integer to the right, use the numpy.right_shift() method in Python Numpy −</p><pre class="result notranslate">print(" Result (right shift)... ",np.right_shift(arr, valRight))</pre><h2>Example</h2><pre class="demo-code notranslate language-numpy" data-lang="numpy">import numpy as np # Create a 0d array arr = np.array(65) # 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 shift valRight = 2 # 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))</pre><h2>Output</h2><pre class="result notranslate">Array... 65 Array datatype... int64 Array Dimensions... 0 Our Array Shape... () Elements in the Array... 1 Result (right shift)... 16</pre>
- Related Questions & Answers
- Shift the bits of integer array elements to the right in Numpy
- Shift the bits of an integer to the left in Numpy
- 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 integer array elements to the left in Numpy
- Shift the bits of an integer to the left and set the count of shifts as an array in Numpy
- Shift the bits of array elements of a Two-Dimensional array 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?
- Java Program to shift array elements to the right
- How to shift the colorbar position to right in matplotlib?
- JavaScript Reverse the order of the bits in a given integer
- Python Program to Count set bits in an integer
- Java Program to Count set bits in an integer
- Count set bits in an integer in C++
Advertisements