numpy.invert() 函数

此函数计算输入数组中整数的按位非结果。 对于有符号整数,返回二进制补码。


示例

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'  
# 比较 13 和 242 的二进制表示,我们发现 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() 函数返回给定宽度的十进制数的二进制表示。

❮ NumPy 二进制运算符