Reputation: 4781
I know array.array
allows to have int/float array. How to have bool array? Memory efficient. so that 1 value is stored as 1 bit. does array
support it?
Upvotes: 2
Views: 183
Reputation: 113978
>>> sys.getsizeof(int)
436
>>> sys.getsizeof(bool)
436
>>> sys.getsizeof(bool())
12
>>> sys.getsizeof(int())
12
>>>
basically even if you could you would not get any space saving ...
this may also be of interest
"sys.getsizeof(int)" returns an unreasonably large value?
Upvotes: 0
Reputation: 6903
As far as I know there is nothing to store booleans this efficiently in native Python, but you can checkout the bitarray library which is I think what you are looking for.
Upvotes: 3