numpy.ma.masked_array.argsort#
method
- ma.masked_array.argsort(axis=<no value>, kind=None, order=None, endwith=True, fill_value=None, *, stable=False)[source]#
Return an ndarray of indices that sort the array along the specified axis. Masked values are filled beforehand to
fill_value
.- Parameters:
- axisint, optional
Axis along which to sort. If None, the default, the flattened array is used.
Changed in version 1.13.0: Previously, the default was documented to be -1, but that was in error. At some future date, the default will change to -1, as originally intended. Until then, the axis should be given explicitly when
arr.ndim > 1
, to avoid a FutureWarning.- kind{‘quicksort’, ‘mergesort’, ‘heapsort’, ‘stable’}, optional
The sorting algorithm used.
- orderlist, optional
When a is an array with fields defined, this argument specifies which fields to compare first, second, etc. Not all fields need be specified.
- endwith{True, False}, optional
Whether missing values (if any) should be treated as the largest values (True) or the smallest values (False) When the array contains unmasked values at the same extremes of the datatype, the ordering of these values and the masked values is undefined.
- fill_valuescalar or None, optional
Value used internally for the masked values. If
fill_value
is not None, it supersedesendwith
.- stablebool, optional
Only for compatibility with
np.argsort
. Ignored.
- Returns:
- index_arrayndarray, int
Array of indices that sort a along the specified axis. In other words,
a[index_array]
yields a sorted a.
See also
ma.MaskedArray.sort
Describes sorting algorithms used.
lexsort
Indirect stable sort with multiple keys.
numpy.ndarray.sort
Inplace sort.
Notes
See
sort
for notes on the different sorting algorithms.Examples
>>> import numpy as np >>> a = np.ma.array([3,2,1], mask=[False, False, True]) >>> a masked_array(data=[3, 2, --], mask=[False, False, True], fill_value=999999) >>> a.argsort() array([1, 0, 2])