NumPy 中的 倒置运算符函数

首页 / Numpy入门教程 / NumPy 中的 倒置运算符函数

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

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)

其输出如下-

无涯教程网

链接:https://www.learnfk.comhttps://www.learnfk.com/numpy/numpy-invert.html

来源:LearnFk无涯教程网

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

Binary representation of 13:
00001101

Binary representation of 242:
11110010

请注意, np.binary_repr()函数以给定的宽度返回十进制数的二进制表示形式。

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

React实战进阶45讲 -〔王沛〕

程序员进阶攻略 -〔胡峰〕

性能工程高手课 -〔庄振运〕

陶辉的网络协议集训班02期 -〔陶辉〕

手把手带你写一个Web框架 -〔叶剑峰〕

手把手带你搭建秒杀系统 -〔佘志东〕

Kubernetes入门实战课 -〔罗剑锋〕

B端产品经理入门课 -〔董小圣〕

结构思考力 · 透过结构看思考 -〔李忠秋〕

好记忆不如烂笔头。留下您的足迹吧 :)