NumPy right_shift


所述 numpy.right_shift() 函数通过指定位置中的数组元素向右的二进制表示的比特移位,和0的数目相等的从左侧追加。

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.

其产出如下

Right shift 40 by two positions:
10

Binary representation of 40:
00101000

Binary representation of 10
00001010