numpy.unpackbits()
numpy.unpackbits
numpy.unpackbits(myarray, axis=None)-
Unpacks elements of a uint8 array into a binary-valued output array.
Each element of myarray represents a bit-field that should be unpacked into a binary-valued output array. The shape of the output array is either 1-D (if axis is None) or the same shape as the input array with unpacking done along the axis specified.
Parameters: - myarray : ndarray, uint8 type
-
Input array.
- axis : int, optional
-
The dimension over which bit-unpacking is done.
Noneimplies unpacking the flattened array.
Returns: - unpacked : ndarray, uint8 type
-
The elements are binary-valued (0 or 1).
See also
packbits- Packs the elements of a binary-valued array into bits in a uint8 array.
Examples
>>>>>> a = np.array([[2], [7], [23]], dtype=np.uint8)
>>> a
array([[ 2],
[ 7],
[23]], dtype=uint8)
>>> b = np.unpackbits(a, axis=1)
>>> b
array([[0, 0, 0, 0, 0, 0, 1, 0],
[0, 0, 0, 0, 0, 1, 1, 1],
[0, 0, 0, 1, 0, 1, 1, 1]], dtype=uint8)import numpy as np
largest_number = 10print(range(largest_number))
for i in range(largest_number):
print(i)
print(range, 'range')print(np.array([range(largest_number)],dtype=np.uint8),'np.array([range(largest_number)],dtype=np.uint8)')
print(np.array([range(largest_number)],dtype=np.uint8).T,'np.array([range(largest_number)],dtype=np.uint8).T')binary = np.unpackbits(
np.array([range(largest_number)],dtype=np.uint8),axis=1)
print(binary[0])binary = np.unpackbits(
np.array([range(largest_number)],dtype=np.uint8).T,axis=1)
print(binary[0])
print(binary)'''
range(0, 10)
0
1
2
3
4
5
6
7
8
9
<class 'range'> range
[[0 1 2 3 4 5 6 7 8 9]] np.array([range(largest_number)],dtype=np.uint8)
[[0]
[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]] np.array([range(largest_number)],dtype=np.uint8).T
[0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0
1 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 1 1 0 0 0 0 0 0 1 1 1 0 0 0 0 1 0 0 0 0 0
0 0 1 0 0 1]
[0 0 0 0 0 0 0 0]
[[0 0 0 0 0 0 0 0]
[0 0 0 0 0 0 0 1]
[0 0 0 0 0 0 1 0]
[0 0 0 0 0 0 1 1]
[0 0 0 0 0 1 0 0]
[0 0 0 0 0 1 0 1]
[0 0 0 0 0 1 1 0]
[0 0 0 0 0 1 1 1]
[0 0 0 0 1 0 0 0]
[0 0 0 0 1 0 0 1]]---------------------
作者:wyx100
来源:CSDN
原文:https://blog.csdn.net/wyx100/article/details/80500851
版权声明:本文为博主原创文章,转载请附上博文链接!
numpy.unpackbits()的更多相关文章
- Numpy应用100问
对于从事机器学习的人,python+numpy+scipy+matplotlib是重要的基础:它们基本与matlab相同,而其中最重要的当属numpy:因此,这里列出100个关于numpy函数的问题, ...
- [转]numpy 100道练习题
100 numpy exercise 翻译:YingJoy 网址: https://www.yingjoy.cn/ 来源:https://github.com/rougier/numpy-100 Nu ...
- 100 numpy exercises
100 numpy exercises A joint effort of the numpy community The goal is both to offer a quick referenc ...
- numpy函数查询手册
写了个程序,对Numpy的绝大部分函数及其说明进行了中文翻译. 原网址:https://docs.scipy.org/doc/numpy/reference/routines.html#routine ...
- 利用Python进行数据分析(5) NumPy基础: ndarray索引和切片
概念理解 索引即通过一个无符号整数值获取数组里的值. 切片即对数组里某个片段的描述. 一维数组 一维数组的索引 一维数组的索引和Python列表的功能类似: 一维数组的切片 一维数组的切片语法格式为a ...
- 利用Python进行数据分析(4) NumPy基础: ndarray简单介绍
一.NumPy 是什么 NumPy 是 Python 科学计算的基础包,它专为进行严格的数字处理而产生.在之前的随笔里已有更加详细的介绍,这里不再赘述. 利用 Python 进行数据分析(一)简单介绍 ...
- 利用Python进行数据分析(6) NumPy基础: 矢量计算
矢量化指的是用数组表达式代替循环来操作数组里的每个元素. NumPy提供的通用函数(既ufunc函数)是一种对ndarray中的数据进行元素级别运算的函数. 例如,square函数计算各元素的平方,r ...
- python安装numpy、scipy和matplotlib等whl包的方法
最近装了python和PyCharm开发环境,但是在安装numpy和matplotlib等包时出现了问题,现总结一下在windows平台下的安装方法. 由于现在找不到了工具包新版本的exe文件,所以采 ...
- 深入理解numpy
一.为啥需要numpy python虽然说注重优雅简洁,但它终究是需要考虑效率的.别说运行速度不是瓶颈,在科学计算中运行速度就是瓶颈. python的列表,跟java一样,其实只是一维列表.一维列表相 ...
随机推荐
- 第15章 高并发服务器编程(1)_非阻塞I/O模型
1. 高性能I/O (1)通常,recv函数没有数据可用时会阻塞等待.同样,当socket发送缓冲区没有足够多空间来发送消息时,函数send会阻塞. (2)当socket在非阻塞模式下,这些函数不会阻 ...
- GameObject数组
一.声明 GameObject[] rock = ]; 二.遍历 可以先声明一个GameObject的数组GameObject[], 然后把需要遍历的对象放进去,然后可以用下面两种方式遍历:1.for ...
- 库、教程、论文实现,这是一份超全的PyTorch资源列表(Github 2.2K星)
项目地址:https://github.com/bharathgs/Awesome-pytorch-list 列表结构: NLP 与语音处理 计算机视觉 概率/生成库 其他库 教程与示例 论文实现 P ...
- 包与常用模块:time,sys。
一 包的初识: 首先包在pycharm中的表现形式为packa文件夹:在python3种那么我们创建一个packa时会发现下边会自动跟一个—init—.py文件 包的定义:包就是一个包含有——ini ...
- C# WebBrowser
WebBrowser中的按钮调用WinForm中的事件: private void Form1_Load(object sender, EventArgs e) { this.webBrowser1. ...
- linux运维工程师工作中的一些常见问题解决方法
http://blog.sina.com.cn/s/blog_b9fe247a0101anoe.html 1.shell脚本死活不执行 问题:某天研发某同事找我说帮他看看他写的shell脚本,死活不执 ...
- linux添加计划任务
crond 是linux用来定期执行程序的命令.当安装完成操作系统之后,默认便会启动此任务调度命令.crond命令每分锺会定期检查是否有要执行的工作,如果有要执行的工作便会自动执行该工作.可以用以下的 ...
- python正则表达式re库(自用)
经典例子: 1.由26个字母组成的字符串 ^[A-Za-z]+$ 2. 中国境内邮政编码 [1-9]\d{5} 3.IP地址 0-99:[1-9]?\d 100-199:1\d{2} 200-249: ...
- 不丢失log的情况下迁移git空间
背景: 原来的源码都放在个人的空间下,为了团队后续规范管理,建立了一个团队使用的空间,需要把旧空间的文件和提交记录,一起迁移. 方法:git remote 进行空间切换 1.查看当前空间名:git r ...
- Ping ip能ping通,ping计算机名ping不通,网络共享不能访问
名称 协议 端口 NetBIOS Name Service UDP 137 NetBIOS Datagram Service UDP 138 NetBIOS Session Service TCP 1 ...