I am using 2d numpy matrices as adjacency matrices for various graph representations and traversals. These are unweighted graphs, and I only need to check for connectivity, nothing more. Therefore, I am using 1s to represent edges, and 0s to represent the lack of an edge.
I acknowledge that the following question probably depends on many factors - most of which are outside of my understanding.
What is the appropriate dtype to use when doing bitwise operations between two matrices of 1s and 0s (or trues and falses)?
I also have a second question - is numpy even the correct choice for this scenario? I am wondering if maybe there is a python package I don't know about that is better than numpy if you are only doing bitwise operations (no arithmetic).
Thank you.
sys.getsizeofto compare different implementationsdtype=bool? It supports bitwise operations out of the box (with &, |, ~ or alternatively with np.logical_and, np.logical_or, np.logical_not) and in my experience it should take care of all the low-level problems. EDIT: well actually it appears to internally use a full byte (like np.int8) so yes, it wastes 7/8th of the space, there might indeed be better options, sorry.