numpy boolean array with 1 bit entries

前端 未结 3 1014
灰色年华
灰色年华 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:42

    You want a bitarray:

    efficient arrays of booleans -- C extension

    This module provides an object type which efficiently represents an array of booleans. Bitarrays are sequence types and behave very much like usual lists. Eight bits are represented by one byte in a contiguous block of memory. The user can select between two representations; little-endian and big-endian. All of the functionality is implemented in C. Methods for accessing the machine representation are provided. This can be useful when bit level access to binary files is required, such as portable bitmap image files (.pbm). Also, when dealing with compressed data which uses variable bit length encoding, you may find this module useful...

提交回复
热议问题