numpy boolean array with 1 bit entries(具有 1 位条目的 numpy 布尔数组)
问题描述
在 numpy 中有没有办法创建一个布尔数组,每个条目只使用 1 位?
Is there a way in numpy to create an array of booleans that uses just 1 bit for each entry?
标准的 np.bool
类型是 1 字节,但是这样我使用了 8 倍的所需内存.
The standard np.bool
type is 1 byte, but this way I use 8 times the required memory.
在 Google 我发现 C++ 有 std::vector<bool>
.
On Google I found that C++ has std::vector<bool>
.
推荐答案
你不妨看看 bitstring(文档这里).
You might like to take a look at bitstring (documentation here).
如果你从一个文件创建一个 ConstBitArray
或 ConstBitStream
那么它将使用 mmap
而不会将它加载到内存中.在这种情况下,它不会是可变的,因此如果您想进行更改,则必须将其加载到内存中.
If you create a ConstBitArray
or ConstBitStream
from a file then it will use mmap
and not load it into memory. In this case it won't be mutable so if you want to make changes it will have to be loaded in memory.
例如创建而不加载到内存中:
For example to create without loading into memory:
>>> a = bitstring.ConstBitArray(filename='your_file')
或
>>> b = bitstring.ConstBitStream(a_file_object)
这篇关于具有 1 位条目的 numpy 布尔数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:具有 1 位条目的 numpy 布尔数组


基础教程推荐
- 包装空间模型 2022-01-01
- 求两个直方图的卷积 2022-01-01
- 使用大型矩阵时禁止 Pycharm 输出中的自动换行符 2022-01-01
- 在Python中从Azure BLOB存储中读取文件 2022-01-01
- 在同一图形上绘制Bokeh的烛台和音量条 2022-01-01
- PermissionError: pip 从 8.1.1 升级到 8.1.2 2022-01-01
- Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙? 2022-01-01
- 无法导入 Pytorch [WinError 126] 找不到指定的模块 2022-01-01
- 修改列表中的数据帧不起作用 2022-01-01
- PANDA VALUE_COUNTS包含GROUP BY之前的所有值 2022-01-01