numpy boolean array with 1 bit entries

前端 未结 3 1015
灰色年华
灰色年华 2020-12-29 19:24

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

The standard np.bool type is 1 byte, but this way I use 8 ti

3条回答
  •  离开以前
    2020-12-29 19:38

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

    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')
    

    or

    >>> b = bitstring.ConstBitStream(a_file_object)
    

提交回复
热议问题