I have some functions, part of a big analysis software, that require a boolean mask to divide array items in two groups. These functions are like this:
def process(data, a_mask):
b_mask = -a_mask
res_a = func_a(data[a_mask])
res_b = func_b(data[b_mask])
return res_a, res_b
Now, I need to use these functions (with no modification) with a big array that has items of only class "a", but I would like to save RAM and do not pass a boolean mask with all True
. For example I could pass a slice like slice(None, None)
.
The problem is that the line b_mask = -a_mask
will fail if a_mask
is a slice. Ideally -a_mask
should give a 0-items selection.
I was thinking of creating a "modified" slice object that implements the __neg__()
method as a null slice (for example slice(0, 0)
). I don't know if this is possible.
Other solutions that allow to don't modify the process()
function but at the same time avoid allocating an all-True boolean array will be accepted as well.