NumPy – right shift

NumPy - right shift

In this chapter, we will discuss about NumPy’s right shift. The numpy.right_shift() function shift the bits in the binary representation of an array element to the right by specified positions, and an equal number of 0s are appended from the left.

Example Of NumPy right shift

import numpy as np 

print 'Right shift 40 by two positions:' 
print np.right_shift(40,2) 
print '\n'  

print 'Binary representation of 40:' 
print np.binary_repr(40, width = 8) 
print '\n'  

print 'Binary representation of 10' 
print np.binary_repr(10, width = 8)  
# Two bits in '00001010' are shifted to right and two 0s appended from left.

Its output would be as follows −

Right shift 40 by two positions:
10

Binary representation of 40:
00101000

Binary representation of 10
00001010

Next Topic- Click Here

This Post Has 2 Comments

Leave a Reply