bundles / numpy latest / numpy / ma / core / MaskedArray / take
function
numpy.ma.core:MaskedArray.take
source: build-install/usr/lib/python3.14/site-packages/numpy/ma/core.py:6164
Signature
def take(self, indices, axis = None, out = None, mode = raise)Summary
Take elements from a masked array along an axis.
Extended Summary
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.
Parameters
a: masked_arrayThe source masked array.
indices: array_likeThe indices of the values to extract. Also allow scalars for indices.
axis: int, optionalThe axis over which to select values. By default, the flattened input array is used.
out: MaskedArray, optionalIf provided, the result will be placed in this array. It should be of the appropriate shape and dtype. Note that
outis always buffered ifmode='raise'; use other modes for better performance.mode: {'raise', 'wrap', 'clip'}, optionalSpecifies how out-of-bounds indices will behave.
'raise' -- raise an error (default)
'wrap' -- wrap around
'clip' -- clip to the range
'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.
Returns
out: MaskedArrayThe returned array has the same type as a.
Notes
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.
Examples
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)When `indices` is not one-dimensional, the output also has these dimensions:
np.ma.take(a, [[0, 1], [2, 3]])
See also
- compress
Take elements using a boolean mask.
- numpy.take
Equivalent function for ndarrays.
- take_along_axis
Take elements by matching the array and the index arrays.
Aliases
numpy.ma.MaskedArray.take