<div><div dir="auto">Thanks. I’m aware of bool arrays.</div></div><div dir="auto">I think the tricky part of what I’m looking for is NULLability and interoperability with code the deals with billable data (float arrays).</div><div dir="auto"><br></div><div dir="auto">Currently the options seem to be float arrays, or custom operations that carry (unabstracted) categorical array data representations, such as:</div><div dir="auto">0: false</div><div dir="auto">1: true</div><div dir="auto">2: NULL</div><div dir="auto"><br></div><div dir="auto">... which wouldn’t be compatible with algorithms that use, say, np.isnan.</div><div dir="auto">Ideally, it would be nice to have a structure that was float-like in that it’s compatible with nan-aware operations, but it’s storage is just a single byte per cell (or less). </div><div dir="auto"><br></div><div dir="auto">Is float8 a thing?</div><div dir="auto"><br></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 18, 2019 at 9:46 AM Stefan van der Walt <<a href="mailto:stefanv@berkeley.edu">stefanv@berkeley.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Stuart,<br>
<br>
On Thu, 18 Apr 2019 09:12:31 -0700, Stuart Reynolds wrote:<br>
> Is there an efficient way to represent bool arrays with null entries?<br>
<br>
You can use the bool dtype:<br>
<br>
In [5]: x = np.array([True, False, True])                                                                                                                                            <br>
<br>
In [6]: x                                                                                                                                                                            <br>
Out[6]: array([ True, False,  True])<br>
<br>
In [7]: x.dtype                                                                                                                                                                      <br>
Out[7]: dtype('bool')<br>
<br>
You should note that this stores one True/False value per byte, so it is<br>
not optimal in terms of memory use.  There is no easy way to do<br>
bit-arrays with NumPy, because we use strides to determine how to move<br>
from one memory location to the next.<br>
<br>
See also: <a href="https://www.reddit.com/r/Python/comments/5oatp5/one_bit_data_type_in_numpy/" rel="noreferrer" target="_blank">https://www.reddit.com/r/Python/comments/5oatp5/one_bit_data_type_in_numpy/</a><br>
<br>
> What I’m hoping for is that there’s a structure that is ‘viewed’ as<br>
> nan-able float data, but backed but a more efficient structures<br>
> internally.<br>
<br>
There are good implementations of this idea, such as:<br>
<br>
<a href="https://github.com/ilanschnell/bitarray" rel="noreferrer" target="_blank">https://github.com/ilanschnell/bitarray</a><br>
<br>
Those structures cannot typically utilize the NumPy machinery, though.<br>
With the new array function interface, you should at least be able to<br>
build something that has something close to the NumPy API.<br>
<br>
Best regards,<br>
Stéfan<br>
_______________________________________________<br>
NumPy-Discussion mailing list<br>
<a href="mailto:NumPy-Discussion@python.org" target="_blank">NumPy-Discussion@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/numpy-discussion" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/numpy-discussion</a><br>
</blockquote></div></div>