Try:

>>> X[np.ix_(m0, m1)]
array([[ 4,  5,  6],
       [ 8,  9, 10]])

From the docs:

Combining multiple Boolean indexing arrays or a Boolean with an integer indexing array can best be understood with the obj.nonzero() analogy. The function ix_ also supports boolean arrays and will work without any surprises.

Another solution (also straight from the docs but less intuitive IMO):

>>> X[m0.nonzero()[0][:, np.newaxis], m1]
array([[ 4,  5,  6],
       [ 8,  9, 10]])
Answer from not_speshal on Stack Overflow
🌐
Awkward-array
awkward-array.org › doc › main › user-guide › how-to-filter-masked.html
How to filter with arrays containing missing values — Awkward Array 2.9.0 documentation
Awkward reducers accept a mask_identity argument, which changes the ak.Array.type and the values of the result: ak.argmax(array, keepdims=True, axis=-1, mask_identity=False)
🌐
Awkward-array
awkward-array.org › doc › main › reference › ak.behavior.html
ak.behavior — Awkward Array 2.14.0 documentation
If the reducer does not introduce an option type, and mask=True, Awkward will mask the result at the appropriate positions. The reducer should return an ak.Array or ak.contents.Content with the same number of elements as the input array. The reduction itself should be performed along axis=1, ...
🌐
Awkward-array
awkward-array.org › doc › main › user-guide › how-to-math-reducing.html
How to reduce dimensions (sum/min/any/all) — Awkward Array 2.10.0 documentation
Sometimes, you want to replace lists with a length-1 list, rather than a scalar. keepdims=True does that. ... The keepdims argument is particularly useful for ak.argmin() and ak.argmax(), which return positions in a list where the value is minimized or maximized.
🌐
Awkward-array
awkward-array.org › doc › main › reference › generated › ak.sum.html
ak.sum — Awkward Array 2.10.0 documentation
ak.sum(array, axis=None, *, keepdims=False, mask_identity=False, highlevel=True, behavior=None, attrs=None)#
🌐
Awkward-array
awkward-array.org › doc › main › reference › generated › ak.ptp.html
ak.ptp — Awkward Array 2.9.0 documentation
ak.ptp(array, axis=None, *, keepdims=False, mask_identity=True, highlevel=True, behavior=None, attrs=None)#
Author: scikit-hep
🌐
Awkward-array
awkward-array.org › doc › main › reference › generated › ak.prod.html
ak.prod — Awkward Array 2.14.0 documentation
ak.prod(array, axis=None, *, keepdims=False, mask_identity=False, highlevel=True, behavior=None, attrs=None)#
Find elsewhere
🌐
GitHub
github.com › scikit-hep › awkward-0.x
GitHub - scikit-hep/awkward-0.x: Manipulate arrays of complex data structures as easily as Numpy. · GitHub
Naturally, the only kinds of arrays Numpy can mask are subclasses of its own ndarray, and we need to be able to mask any Awkward Array, so the Awkward library defines its own MaskedArray. Additionally, we sometimes want to mask with bits, rather than bytes (e.g. for Arrow compatibility), so there's a BitMaskedArray, and sometimes we want to mask large structures without using memory for the masked-out values, so there's an IndexedMaskedArray (fusing the functionality of a MaskedArray with an IndexedArray).
Starred by 214 users
Forked by 38 users
Languages: Python 63.7% | Jupyter Notebook 36.3%
🌐
Awkward-array
awkward-array.org › doc › main › reference › generated › ak.contents.UnmaskedArray.html
ak.contents.UnmaskedArray — Awkward Array 2.14.0 documentation
UnmaskedArray implements an ak.types.OptionType for which the values are never, in fact, missing. It exists to satisfy systems that formally require this high-level type without the overhead of generating an array of all True or all False values. This is like NumPy’s masked arrays with mask=None.
🌐
Readthedocs
awkward-array.readthedocs.io › en › latest › _auto › ak.sum.html
ak.sum — Awkward Array documentation
>>> ak.sum(array, axis=-1, keepdims=True) <Array [[0.6], None, [60.6], [90.6]] type='4 * option[1 * float64]'> >>> ak.sum(array, axis=0, keepdims=True) <Array [[50.3, 50.6, 50.9]] type='1 * var * float64'> and axis=None ignores all None values and adds up everything in the array (keepdims has no effect). ... The mask_identity, which has no equivalent in NumPy, inserts None in the output wherever a reduction takes place over zero elements.
🌐
Awkward-array
awkward-array.org › doc › main › reference › generated › ak.max.html
ak.max — Awkward Array 2.8.10 documentation
ak.max(array, axis=None, *, keepdims=False, initial=None, mask_identity=True, highlevel=True, behavior=None, attrs=None)#
🌐
Awkward-array
awkward-array.org › doc › main › reference › generated › ak.mask.html
ak.mask — Awkward Array 2.13.0 documentation
mask (array of booleans) – The mask that overlays elements in the array with None. Must have the same length as array. valid_when (bool) – If True, True values in mask are considered valid (passed from array to the output); if False, False values in mask are considered valid.
🌐
Readthedocs
awkward-array.readthedocs.io › en › latest › _auto › ak.argmax.html
ak.argmax — Awkward Array documentation
keepdims (bool) – If False, this reducer decreases the number of dimensions by 1; if True, the reduced values are wrapped in a new length-1 dimension so that the result of this operation may be broadcasted with the original array. mask_identity (bool) – If True, reducing over empty lists ...
🌐
Awkward-array
awkward-array.org › doc › main › reference › generated › ak.count.html
ak.count — Awkward Array 2.14.0 documentation
keepdims (bool) – If False, this reducer decreases the number of dimensions by 1; if True, the reduced values are wrapped in a new length-1 dimension so that the result of this operation may be broadcasted with the original array. mask_identity (bool) – If True, reducing over empty lists ...
🌐
Awkward-array
awkward-array.org › doc › main › _sources › user-guide › how-to-convert-numpy.md.txt
--- jupytext: text_representation: extension: .md format_name: myst
{code-cell} ipython3 np_array = np.ma.MaskedArray( [[1, 2, 3], [4, 5, 6]], mask=[[False, True, False], [True, True, False]] ) np_array ... The ? before int64 (expands to option[...] for more complex contents) refers to "option type," meaning that the values can be missing ("None" in Python).
🌐
Edwinwenink
edwinwenink.xyz › posts › 60-masking_with_boolean_arrays_numpy
Masking with Boolean arrays in Numpy - Edwin Wenink
So in our use case we have two arrays, where the second serves as a mask that indicates which elements to keep in the first array. We can use: ... Method 1. We essentially want to keep all elements from arr in the corresponding places where mask is non-zero: ... Python interprets False as 0 and True as 1.
🌐
GitHub
github.com › scikit-hep › awkward › issues › 975
`ak.mask` fails for n-dim `NumpyArray` masks · Issue #975 · scikit-hep/awkward
July 1, 2021 - import awkward as ak import numpy as np array = ak.Array( ak.layout.RegularArray(ak.layout.NumpyArray(np.r_[1, 2, 3, 4, 5, 6, 7, 8, 9]), 3) ) mask = ak.Array(ak.layout.NumpyArray(np.array([ [True, True, True], [True, True, False], [True, False, True] ]))) ak.mask(array, mask) Reactions are currently unavailable ·
Author: scikit-hep