method
Take elements from a masked array along an axis.
This function does the same thing as “fancy” indexing (indexing arrays using arrays) for masked arrays. It can be easier to use if you need elements along a given axis.
The source masked array.
The indices of the values to extract. Also allow scalars for indices.
The axis over which to select values. By default, the flattened input array is used.
If provided, the result will be placed in this array. It should be of the appropriate shape and dtype. Note that out is always buffered if mode=’raise’; use other modes for better performance.
Specifies how out-of-bounds indices will behave.
‘clip’ mode means that all indices that are too large are replaced by the index that addresses the last element along that axis. Note that this disables indexing with negative numbers.
The returned array has the same type as a.
See also
numpy.takeEquivalent function for ndarrays.
compressTake elements using a boolean mask.
take_along_axisTake elements by matching the array and the index arrays.
This function behaves similarly to numpy.take, but it handles masked values. The mask is retained in the output array, and masked values in the input array remain masked in the output.
>>> import numpy as np
>>> a = np.ma.array([4, 3, 5, 7, 6, 8], mask=[0, 0, 1, 0, 1, 0])
>>> indices = [0, 1, 4]
>>> np.ma.take(a, indices)
masked_array(data=[4, 3, --],
mask=[False, False, True],
fill_value=999999)
When indices is not one-dimensional, the output also has these dimensions:
>>> np.ma.take(a, [[0, 1], [2, 3]])
masked_array(data=[[4, 3],
[--, 7]],
mask=[[False, False],
[ True, False]],
fill_value=999999)
© 2005–2024 NumPy Developers
Licensed under the 3-clause BSD License.
https://numpy.org/doc/2.4/reference/generated/numpy.ma.MaskedArray.take.html