MCPcopy
hub / github.com/numpy/numpy / take

Method take

numpy/ma/core.py:6180–6269  ·  view source on GitHub ↗

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. Parameters ---------- a

(self, indices, axis=None, out=None, mode='raise')

Source from the content-addressed store, hash-verified

6178 return super().argpartition(*args, **kwargs)
6179
6180 def take(self, indices, axis=None, out=None, mode='raise'):
6181 """
6182 Take elements from a masked array along an axis.
6183
6184 This function does the same thing as "fancy" indexing (indexing arrays
6185 using arrays) for masked arrays. It can be easier to use if you need
6186 elements along a given axis.
6187
6188 Parameters
6189 ----------
6190 a : masked_array
6191 The source masked array.
6192 indices : array_like
6193 The indices of the values to extract. Also allow scalars for indices.
6194 axis : int, optional
6195 The axis over which to select values. By default, the flattened
6196 input array is used.
6197 out : MaskedArray, optional
6198 If provided, the result will be placed in this array. It should
6199 be of the appropriate shape and dtype. Note that `out` is always
6200 buffered if `mode='raise'`; use other modes for better performance.
6201 mode : {'raise', 'wrap', 'clip'}, optional
6202 Specifies how out-of-bounds indices will behave.
6203
6204 * 'raise' -- raise an error (default)
6205 * 'wrap' -- wrap around
6206 * 'clip' -- clip to the range
6207
6208 'clip' mode means that all indices that are too large are replaced
6209 by the index that addresses the last element along that axis. Note
6210 that this disables indexing with negative numbers.
6211
6212 Returns
6213 -------
6214 out : MaskedArray
6215 The returned array has the same type as `a`.
6216
6217 See Also
6218 --------
6219 numpy.take : Equivalent function for ndarrays.
6220 compress : Take elements using a boolean mask.
6221 take_along_axis : Take elements by matching the array and the index arrays.
6222
6223 Notes
6224 -----
6225 This function behaves similarly to `numpy.take`, but it handles masked
6226 values. The mask is retained in the output array, and masked values
6227 in the input array remain masked in the output.
6228
6229 Examples
6230 --------
6231 >>> import numpy as np
6232 >>> a = np.ma.array([4, 3, 5, 7, 6, 8], mask=[0, 0, 1, 0, 1, 0])
6233 >>> indices = [0, 1, 4]
6234 >>> np.ma.take(a, indices)
6235 masked_array(data=[4, 3, --],
6236 mask=[False, False, True],
6237 fill_value=999999)

Callers 15

test_takeFunction · 0.80
test_take_outputMethod · 0.80
test_take_object_failMethod · 0.80
test_attributesMethod · 0.80
test_take_refcountMethod · 0.80
tst_basicMethod · 0.80
test_raiseMethod · 0.80
test_clipMethod · 0.80
test_wrapMethod · 0.80

Calls 4

getmaskFunction · 0.85
__setmask__Method · 0.80
filledMethod · 0.45
viewMethod · 0.45

Tested by 15

test_takeFunction · 0.64
test_take_outputMethod · 0.64
test_take_object_failMethod · 0.64
test_attributesMethod · 0.64
test_take_refcountMethod · 0.64
tst_basicMethod · 0.64
test_raiseMethod · 0.64
test_clipMethod · 0.64
test_wrapMethod · 0.64