numpy.ma.MaskedArray.sort#
method
- ma.MaskedArray.sort(axis=-1,kind=None,order=None,endwith=True,fill_value=None,*,stable=False)[source]#
Sort the array, in-place
- Parameters:
- aarray_like
Array to be sorted.
- axisint, optional
Axis along which to sort. If None, the array is flattened beforesorting. The default is -1, which sorts along the last axis.
- kind{‘quicksort’, ‘mergesort’, ‘heapsort’, ‘stable’}, optional
The sorting algorithm used.
- orderlist, optional
Whena is a structured array, this argument specifies which fieldsto compare first, second, and so on. This list does not need toinclude all of the fields.
- 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 sorting at the same extremes of thedatatype, the ordering of these values and the masked values isundefined.
- fill_valuescalar or None, optional
Value used internally for the masked values.If
fill_valueis not None, it supersedesendwith.- stablebool, optional
Only for compatibility with
np.sort. Ignored.
- Returns:
- sorted_arrayndarray
Array of the same type and shape asa.
See also
numpy.ndarray.sortMethod to sort an array in-place.
argsortIndirect sort.
lexsortIndirect stable sort on multiple keys.
searchsortedFind elements in a sorted array.
Notes
See
sortfor notes on the different sorting algorithms.Examples
>>>importnumpyasnp>>>a=np.ma.array([1,2,5,4,3],mask=[0,1,0,1,0])>>># Default>>>a.sort()>>>amasked_array(data=[1, 3, 5, --, --], mask=[False, False, False, True, True], fill_value=999999)
>>>a=np.ma.array([1,2,5,4,3],mask=[0,1,0,1,0])>>># Put missing values in the front>>>a.sort(endwith=False)>>>amasked_array(data=[--, --, 1, 3, 5], mask=[ True, True, False, False, False], fill_value=999999)
>>>a=np.ma.array([1,2,5,4,3],mask=[0,1,0,1,0])>>># fill_value takes over endwith>>>a.sort(endwith=False,fill_value=3)>>>amasked_array(data=[1, --, --, 3, 5], mask=[False, True, True, False, False], fill_value=999999)