Numpy-left-shift

提供:Dev Guides
移動先:案内検索

NumPy-left_shift

  • 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