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一样,其实只是一维列表.一维列表相 ...
随机推荐
- java判断字符串中是否含有中文
/** * 判断字符串中是否含有中文 */ public static boolean isCNChar(String s){ boolean booleanValue = false; for(in ...
- ASP.NET Web Pages:C# 和 VB 实例
ylbtech-.Net-ASP.NET Web Pages:C# 和 VB 实例 1.返回顶部 1. ASP.NET Web Pages - C# 和 VB 实例 通过 C# 和 Visual Ba ...
- [UE4]动态数组:TArray容器
为什么使用UE4提供的容器类? 如果你用过C++的STL库,你就知道STL提供了各种各样的容器/数据结构,使得你对处理很多数据的时候非常快捷高效.UE4同样也提供了类似的库,库里面的类型是以T开头的, ...
- mysql存储过程的参数名不要跟字段名一样 (血淋淋的代价)
如题,将会导致的结果就是参数的值将不会是你传入的值,而是变成每条记录的那个字段的值. 这样的后果,是灰常严重的.比如执行删除操作,它能把整个表的记录全删了. 这个是我的血淋淋的代价啊. 死坑如下,勿跳 ...
- linux中的ftp命令
转载至:https://www.cnblogs.com/mingforyou/p/4103022.html 一.ftp的get命令和mget命令有何不同? get一次只下载一个文件:mget一次可以下 ...
- 战争迷雾Fog Of War
参考:https://forums.unrealengine.com/community/community-content-tools-and-tutorials/26436-tutorial-fo ...
- BCGcontrolBar(五) 对话框大小改变控件自动适应
改变控件大小 首先在 构造函数中加入 EnableLayout(); 在OnInitDialog()函数中加入 CBCGPStaticLayout* pLayout = (CBCGPStaticLay ...
- webpack(5)--Resolve
Resolve webpack在启动后会从配置的入口模块触发找出所有依赖的模块,Resolve配置webpack如何寻找模块对应的文件.webpack内置JavaScript模块化语法解析功能,默认会 ...
- JQ 确定与取消弹出框,选择确定执行Ajax
$(function () { $("#GetCoupon").click(function () { function del() { var msg = "请确定领取 ...
- 19.XPath选择器
1.extract():提取数据 2./text() :获取节点内容文本 3./@href :获取节点href属性 4. @ :获取属性名称 需要注意问题: 用定义的规则那 ...