Is there a way in numpy to create an array of booleans that uses just 1 bit for each entry?

有没有办法在numpy中创建一个布尔数组,每个条目只使用1位?

The standard np.bool type is 1 byte, but this way I use 8 times the required memory.

标准的np.bool类型是1个字节,但这样我使用所需内存的8倍。

On Google I found that C++ has std::vector<bool>.

在谷歌上我发现C ++有std :: vector

3 个解决方案

#1


10

You might like to take a look at bitstring (documentation here).

您可能想看看bitstring(这里的文档)。

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.

如果从文件创建ConstBitArray或ConstBitStream,则它将使用mmap而不将其加载到内存中。在这种情况下,它不会是可变的,所以如果你想进行更改,它必须加载到内存中。

For example to create without loading into memory:

例如,无需加载到内存中即可创建:

>>> a = bitstring.ConstBitArray(filename='your_file')

or

>>> b = bitstring.ConstBitStream(a_file_object)

更多相关文章

  1. Django:测试成功加载静态文件
  2. 使用python 3.6将多个文件并行加载到内存中的最佳方法是什么?
  3. 每次部署站点时,如何使用Google App Engine清除内存缓存?
  4. 基于python的opcode优化和模块按需加载机制研究(学习与个人思路)
  5. python中查看变量内存地址的方法
  6. ARM11、OK6410_Linux、系统移植 和 驱动加载
  7. [caffe(二)]Python加载训练caffe模型并进行测试2
  8. Linux下共享内存相关函数
  9. [Linux OS] Ubuntu 16.04 上实时显示上下行网速、CPU及内存使用

随机推荐

  1. Android Factory Reset flow
  2. Android 读取MCC, MNC
  3. listView 多值显示
  4. android 键盘显示与隐藏
  5. [摘]android:windowSoftInputMode属性使
  6. Android(安卓)MediaPlayer类详解
  7. Android中对于Bitmap的处理
  8. Android编译系统中的Kconfig,Makefile,.co
  9. Android NDK: Your APP_BUILD_SCRIPT poi
  10. android gallery的使用