-
I would like to check if my array is masked. If it is masked, I need to apply some extra logic. Example: a = ak.unflatten([1,2,3,4,5], [2,2,1])
b = ak.mask(a, a != 1) Now if I call a function on |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
We don't as-yet have a routine to do this. A "hacky" way is to check the type string, but if you want to specify an axis, we should write a proper visitor to do this. Your proposed function might look something like this: def is_masked(array, axis=1):
# To support Py 2, we can't use nonlocal
state = {
"posaxis": axis,
"is_mask": False
}
def apply(layout, depth):
posaxis = state['posaxis'] = layout.axis_wrap_if_negative(state['posaxis'])
if (depth == posaxis + 1) and isinstance(layout, ak._util.optiontypes):
state['is_mask'] = True
layout = ak.to_layout(array)
ak._util.recursive_walk(layout, apply)
return state['is_mask'] It's not perfect (we don't exit out early once we find the right axis), but it demonstrates the point. |
Beta Was this translation helpful? Give feedback.
We don't as-yet have a routine to do this. A "hacky" way is to check the type string, but if you want to specify an axis, we should write a proper visitor to do this. Your proposed function might look something like this: