Python-Numpy库中的invert()函数的用法
官方解释:
Compute bit-wise inversion, or bit-wise NOT, element-wise.
Computes the bit-wise NOT of the underlying binary representation of the integers in the input arrays.
For signed integer inputs, the two’s complement is returned. In a two’s-complement system negative numbers are represented by the two’s complement of the absolute value. This is the most common method of representing signed integers on computers [1]. A N-bit two’s-complement system can represent every integer in the range −2N−1 -2^{N-1}−2
函数invert()计算输入数组中整数的二进制按位NOT结果. 也就是说 Numpy库中的bitwise_not() 和 invert()是一个函数,作用相同,只是名字不同. 验证一下发现两者其实是相等的:
>>>np.bitwise_not is np.invert
True
下面举例来看invert函数的作用. 官网的例子,我们知道整数"13"以二进制表示为"00001101",将13进行invert()转化有 :
>>> np.invert(np.arange([13], dtype=unit8))
array([242],dtype=unit8)
输出的是242,这个242又是什么呢? 将242转换成二进制数:
>>> np.binary_repr(242, width=8)
'11110010'
这里np.binary_repr() 函数返回给定宽度中十进制数的二进制表示形式。
由输出结果可以发现,"242"的二进制表示“”11110010“”其实就是"00001101"的按位取否.
输出的结果取决于bit_width
当dtype取unit16时,结果会变得不同:
>>> np.invert(np.array([13], dtype=uint16))
array([65522], dtype=uint16)
>>> np.binary_repr(x, width=16)
'0000000000001101'
>>> np.binary_repr(65522, width=16)
'1111111111110010'
当使用含符号整数类型"int8"时,结果是无符号类型的结果的二进制补码:
>>> np.invert(np.array([13], dtype=int8))
array([-14], dtype=int8)
>>> np.binary_repr(-14, width=8)
'11110010'
参考资料
【1】 numpy.invert——Numpy
原文:https://blog.csdn.net/Sarah_LZ/article/details/86419606
Python-Numpy库中的invert()函数的用法相关推荐
- Python:Numpy库中的invert()函数的用法
Numpy库中的invert()函数的用法 官方解释: Compute bit-wise inversion, or bit-wise NOT, element-wise. Computes the ...
- Python:numpy库中的一些函数简介、使用方法之详细攻略
Python:numpy库中的一些函数简介.使用方法之详细攻略 目录 numpy库中的一些函数简介.使用方法 1.np.concatenate() 1.1.函数案例 1.2.函数用法 numpy库中的 ...
- python自带的sum()函数和numpy库中的sum()函数的区别
在学习<机器学习实战>一书的第十章时,对 return np.sqrt(sum(np.power(vecA - vecB, 2))) 这样一条语句输出的结果老是不对,明明想要输出的是对两个 ...
- python中mean的用法_python 的numpy库中的mean()函数用法介绍
1. mean() 函数定义: numpy.mean(a, axis=None, dtype=None, out=None, keepdims=)[source] Compute the arithm ...
- python 的numpy库中的mean()函数用法介绍
这篇文章主要介绍了python 的numpy库中的mean()函数用法介绍,具有很好对参考价值,希望对大家有所帮助.一起跟随小编过来看看吧 mean() 函数定义: 2 mean()函数功能: 求取均 ...
- python average函数怎么用_python 的numpy库中的mean()函数用法介绍
1. mean() 函数定义: numpy.mean(a, axis=None, dtype=None, out=None, keepdims=)[source] Compute the arithm ...
- python numpy库中省略号...的一些用法
在学习<Designing Machine Learning Systems with Python>(<机器学习系统设计Python语言实现>)一书的第五章梯度下降一节代码中 ...
- python 的numpy库中的mean()函数用法
1. mean() 函数定义: numpy. mean ( a, axis=None, dtype=None, out=None, keepdims=<class numpy._glob ...
- (原创)机器学习之numpy库中常用的函数介绍(一)
1. mat() mat()与array的区别: mat是矩阵,数据必须是2维的,是array的子集,包含array的所有特性,所做的运算都是针对矩阵来进行的. array是数组,数据可以是多维的,所 ...
最新文章
- 最大字段和(动态规划,C语言)
- 2清空所有表_拉链表(二)
- 【 HDU - 5093】Battle ships(匈牙利算法,二分图匹配)
- [bbk2908]第4集 - Chapter 03 - 介绍RAC的体系结构
- ssh本地端口转发,远程端口转发,隧道(这个解释不饶)
- vmware-设置共享文件夹
- Scikit-learn 更新至0.24版,这10个新特性你需要了解
- 【MyBatis笔记】01-MyBatis入门程序
- eoe·Android 开发门户 - android开发者的必备网站
- java从内存角度理解类变量_深入理解volatile类型——从Java虚拟机内存模型角度...
- 反向传播算法(BP)学习笔记
- 会议及作用篇--项目管理(十三)
- log4j配置(很详细)
- 微信小程序修改BUTTON点击态样式
- 企业级数据服务总线规划
- Excel操作-跳过隐藏行粘贴
- 解释什么是啸叫,为什么会发生啸叫,啸叫的为何和如何防止啸叫
- 转载黑苹果10.13N卡驱动方法
- 元宇宙照进现实 金蝶联手科大讯飞发布“数字员工”
- arduino mega针脚_Arduino MEGA串口TX1、RX1使用方法