当前位置: 首页 > 文档资料 > NumPy 中文教程 >

left_shift

优质
小牛编辑
135浏览
2023-12-01

numpy.left_shift()函数将数组元素的二进制表示中的位向左移动指定的位置。 从右侧追加相等数量的0。

例如,

import numpy as np 
print 'Left shift of 10 by two positions:' 
print np.left_shift(10,2) 
print '\n'  
print 'Binary representation of 10:' 
print np.binary_repr(10, width = 8) 
print '\n'  
print 'Binary representation of 40:' 
print np.binary_repr(40, width = 8)  
# Two bits in '00001010' are shifted to left and two 0s appended from right.

其输出如下 -

Left shift of 10 by two positions:
40
Binary representation of 10:
00001010
Binary representation of 40:
00101000