Numpy-right-shift

提供:Dev Guides
2020年6月23日 (火) 03:12時点におけるMaintenance script (トーク | 投稿記録)による版 (Imported from text file)
(差分) ← 古い版 | 最新版 (差分) | 新しい版 → (差分)
移動先:案内検索

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