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.
None
implies 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一样,其实只是一维列表.一维列表相 ...
随机推荐
- Windows下永久解决数据库乱码 utf8 转 gbk
产生乱码原因 因为windows终端的默认字符集是gbk编码,而mysql数据库是utf8的编码,所以会产生乱码问题 解决乱码问题(临时修改) 询当前数据库默认编码: mysql> show v ...
- Java设计原则之里氏替换原则
里氏代换原则由2008年图灵奖得主.美国第一位计算机科学女博士Barbara Liskov教授和卡内基·梅隆大学Jeannette Wing教授于1994年提出.其严格表述如下:如果对每一个类型为S的 ...
- Parquet列式存储格式
Parquet是面向分析型业务的列式存储格式,由Twitter和Cloudera合作开发,2015年5月从Apache的孵化器里毕业成为Apache顶级项目,最新的版本是1.8.0. 列式存储 列式存 ...
- 1035 Password (20 分)
1035 Password (20 分) To prepare for PAT, the judge sometimes has to generate random passwords for th ...
- Introducing Deep Reinforcement
The manuscript of Deep Reinforcement Learning is available now! It makes significant improvements to ...
- Linux火焰图-ubuntu
关注火焰图非常长的时间了!~~一直未能自己做个火焰图出来.今天小试一把. ubuntu18.04 ssh登陆之后执行命令 安装软件 apt-get install -y linux-cloud-too ...
- IO模式调查利器blkiomon介绍
本文链接地址: IO模式调查利器blkiomon介绍 blkiomon 是blktrace工具包带的一个方便用户了解IO情况的工具, 由于blktrace太专业,需要了解的IO协议栈的东西太多,blk ...
- tornado-输出,request
3种输出方法:write render redirectimport tornado.ioloop import tornado.web import tornado.httpserver # 非阻塞 ...
- 《GPU高性能编程CUDA实战》第十一章 多GPU系统的CUDA C
▶ 本章介绍了多设备胸膛下的 CUDA 编程,以及一些特殊存储类型对计算速度的影响 ● 显存和零拷贝内存的拷贝与计算对比 #include <stdio.h> #include " ...
- leetcode404
/** * Definition for a binary tree node. * public class TreeNode { * public int val; * public TreeNo ...