Numpy-invert

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

numpy.invert()

この関数は、入力配列の整数のビットごとのNOT結果を計算します。 符号付き整数の場合、2の補数が返されます。

import numpy as np

print 'Invert of 13 where dtype of ndarray is uint8:'
print np.invert(np.array([13], dtype = np.uint8))
print '\n'
# Comparing binary representation of 13 and 242, we find the inversion of bits

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

print 'Binary representation of 242:'
print np.binary_repr(242, width = 8)

その出力は次のとおりです-

Invert of 13 where dtype of ndarray is uint8:
[242]

Binary representation of 13:
00001101

Binary representation of 242:
11110010
  • np.binary_repr()*関数は、指定された幅の10進数のバイナリ表現を返すことに注意してください。