Python: NumPy Boolean Data Type
I have been learning Python - more specifically NumPy and Pandas, and came across this.
NumPy stores the Boolean Data Types (True/False) as 8 bits or 1 byte.
As a data engineer, my immediate reaction was, "That is a wasteful allocation of resources. Why did they do this?" Surely they could achieve this with 1 bit?
Well, if you look a bit deeper, there is a very good reason.
NumPy optimizes for speed, not minimal memory.
NumPy uses 1 byte per boolean because:
So yes: it uses more memory, but computation is dramatically faster.