Skip to content

Commit 43a8cd2

Browse files
committed
Added docstring for numpy.ma.take() function.
1 parent 2ce3c19 commit 43a8cd2

File tree

1 file changed

+67
-2
lines changed

1 file changed

+67
-2
lines changed

numpy/ma/core.py

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6211,8 +6211,72 @@ def argpartition(self, *args, **kwargs):
62116211

62126212
def take(self, indices, axis=None, out=None, mode='raise'):
62136213
"""
6214-
"""
6215-
(_data, _mask) = (self._data, self._mask)
6214+
Take elements from a masked array along an axis.
6215+
6216+
This function does the same thing as "fancy" indexing (indexing arrays
6217+
using arrays) for masked arrays. It can be easier to use if you need
6218+
elements along a given axis.
6219+
6220+
Parameters
6221+
----------
6222+
a : masked_array
6223+
The source masked array.
6224+
indices : array_like
6225+
The indices of the values to extract. Also allow scalars for indices.
6226+
axis : int, optional
6227+
The axis over which to select values. By default, the flattened
6228+
input array is used.
6229+
out : MaskedArray, optional
6230+
If provided, the result will be placed in this array. It should
6231+
be of the appropriate shape and dtype. Note that `out` is always
6232+
buffered if `mode='raise'`; use other modes for better performance.
6233+
mode : {'raise', 'wrap', 'clip'}, optional
6234+
Specifies how out-of-bounds indices will behave.
6235+
6236+
* 'raise' -- raise an error (default)
6237+
* 'wrap' -- wrap around
6238+
* 'clip' -- clip to the range
6239+
6240+
'clip' mode means that all indices that are too large are replaced
6241+
by the index that addresses the last element along that axis. Note
6242+
that this disables indexing with negative numbers.
6243+
6244+
Returns
6245+
-------
6246+
out : MaskedArray
6247+
The returned array has the same type as `a`.
6248+
6249+
See Also
6250+
--------
6251+
numpy.take : Equivalent function for ndarrays.
6252+
compress : Take elements using a boolean mask.
6253+
take_along_axis : Take elements by matching the array and the index arrays.
6254+
6255+
Notes
6256+
-----
6257+
This function behaves similarly to `numpy.take`, but it handles masked
6258+
values. The mask is retained in the output array, and masked values
6259+
in the input array remain masked in the output.
6260+
6261+
Examples
6262+
--------
6263+
>>> import numpy as np
6264+
>>> a = np.ma.array([4, 3, 5, 7, 6, 8], mask=[0, 0, 1, 0, 1, 0])
6265+
>>> indices = [0, 1, 4]
6266+
>>> np.ma.take(a, indices)
6267+
masked_array(data=[4, 3, --],
6268+
mask=[False, False, True],
6269+
fill_value=999999)
6270+
6271+
When `indices` is not one-dimensional, the output also has these dimensions:
6272+
6273+
>>> np.ma.take(a, [[0, 1], [2, 3]])
6274+
masked_array(data=[[4, 3],
6275+
[--, 7]],
6276+
mask=[[False, False],
6277+
[ True, False]],
6278+
fill_value=999999)
6279+
""" (_data, _mask) = (self._data, self._mask)
62166280
cls = type(self)
62176281
# Make sure the indices are not masked
62186282
maskindices = getmask(indices)
@@ -7097,6 +7161,7 @@ def __call__(self, a, *args, **params):
70977161

70987162
def take(a, indices, axis=None, out=None, mode='raise'):
70997163
"""
7164+
71007165
"""
71017166
a = masked_array(a)
71027167
return a.take(indices, axis=axis, out=out, mode=mode)

0 commit comments

Comments
 (0)