Numpy MaskedArray.argsort() function | Python Last Updated : 27 Sep, 2019 Comments Improve Suggest changes Like Article Like Report In many circumstances, datasets can be incomplete or tainted by the presence of invalid data. For example, a sensor may have failed to record a data, or recorded an invalid value. The numpy.ma module provides a convenient way to address this issue, by introducing masked arrays.Masked arrays are arrays that may have missing or invalid entries. numpy.MaskedArray.argsort() function return an ndarray of indices that sort the array along the specified axis. Masked values are filled beforehand to fill_value. Syntax : numpy.MaskedArray.argsort(axis=None, kind='quicksort', order=None, endwith=True, fill_value=None) Parameters: axis : [None, integer] Axis along which to sort. If None, the default, the flattened array is used. kind : [‘quicksort’, ‘mergesort’, ‘heapsort’] Sorting algorithm. Default is ‘quicksort’. order : [list, optional] When a is an array with fields defined, this argument specifies which fields to compare first, second, etc. 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 are undefined. fill_value : [ var, optional] Value used to fill in the masked values. If None, the output of minimum_fill_value(self._data) is used instead. Return : [ndarray, int]Array of indices that sort a along the specified axis. Code #1 : Python3 # Python program explaining # numpy.MaskedArray.argsort() method # importing numpy as geek # and numpy.ma module as ma import numpy as geek import numpy.ma as ma # creating input array in_arr = geek.array([4, 2, 3, -1, 5]) print ("Input array : ", in_arr) # Now we are creating a masked array # by making third entry as invalid. mask_arr = ma.masked_array(in_arr, mask =[0, 0, 1, 0, 0]) print ("Masked array : ", mask_arr) # applying MaskedArray.argsort methods to mask array out_arr = mask_arr.argsort() print ("output array of indices: ", out_arr) Output: Input array : [ 4 2 3 -1 5] Masked array : [4 2 -- -1 5] output array of indices: [3 1 0 4 2] Code #2 : Python3 # Python program explaining # numpy.MaskedArray.argsort() method # importing numpy as geek # and numpy.ma module as ma import numpy as geek import numpy.ma as ma # creating input array in_arr = geek.array([5, -5, 0, -10, 2]) print ("Input array : ", in_arr) # Now we are creating a masked array # by making first third entry as invalid. mask_arr = ma.masked_array(in_arr, mask =[1, 0, 1, 0, 0]) print ("Masked array : ", mask_arr) # applying MaskedArray.argminmethods to mask array # and filling the masked location by 1 out_arr = mask_arr.argsort(fill_value = 1) print ("output array of indices: ", out_arr) Output: Input array : [ 5 -5 0 -10 2] Masked array : [-- -5 -- -10 2] output array of indices: [3 1 0 2 4] Comment More infoAdvertise with us Next Article Numpy MaskedArray.argsort() function | Python jana_sayantan Follow Improve Article Tags : Python Python-numpy Python numpy-arrayCreation Practice Tags : python Similar Reads Numpy MaskedArray.dot() function | Python numpy.MaskedArray.dot() function is used to calculate the dot product of two mask arrays. Syntax : numpy.ma.dot(arr1, arr2, strict=False) Parameters: arr1, arr2:[ ndarray] Inputs arrays. strict : [bool, optional] Whether masked data are propagated (True) or set to 0 (False) for the computation. Defa 3 min read Numpy MaskedArray.argmin() function | Python In many circumstances, datasets can be incomplete or tainted by the presence of invalid data. For example, a sensor may have failed to record a data, or recorded an invalid value. The numpy.ma module provides a convenient way to address this issue, by introducing masked arrays.Masked arrays are arra 3 min read Numpy MaskedArray.argmax() function | Python In many circumstances, datasets can be incomplete or tainted by the presence of invalid data. For example, a sensor may have failed to record a data, or recorded an invalid value. The numpy.ma module provides a convenient way to address this issue, by introducing masked arrays.Masked arrays are arra 3 min read Numpy MaskedArray.astype() function | Python In many circumstances, datasets can be incomplete or tainted by the presence of invalid data. For example, a sensor may have failed to record a data, or recorded an invalid value. The numpy.ma module provides a convenient way to address this issue, by introducing masked arrays.Masked arrays are arra 2 min read Numpy MaskedArray.anom() function | Python In many circumstances, datasets can be incomplete or tainted by the presence of invalid data. For example, a sensor may have failed to record a data, or recorded an invalid value. The numpy.ma module provides a convenient way to address this issue, by introducing masked arrays.Masked arrays are arra 2 min read Numpy MaskedArray.all() function | Python In many circumstances, datasets can be incomplete or tainted by the presence of invalid data. For example, a sensor may have failed to record a data, or recorded an invalid value. The numpy.ma module provides a convenient way to address this issue, by introducing masked arrays. Masked arrays are arr 3 min read Numpy MaskedArray.any() function | Python In many circumstances, datasets can be incomplete or tainted by the presence of invalid data. For example, a sensor may have failed to record a data, or recorded an invalid value. The numpy.ma module provides a convenient way to address this issue, by introducing masked arrays.Masked arrays are arra 3 min read Numpy MaskedArray.average() function | Python numpy.MaskedArray.average() function is used to return the weighted average of array over the given axis. Syntax : numpy.ma.average(arr, axis=None, weights=None, returned=False) Parameters: arr :[ array_like] Input masked array whose data to be averaged. Masked entries are not taken into account in 3 min read Numpy MaskedArray.flatten() function | Python numpy.MaskedArray.flatten() function is used to return a copy of the input masked array collapsed into one dimension. Syntax : numpy.ma.flatten(order='C') Parameters: order : [âCâ, âFâ, âAâ, âKâ, optional] Whether to flatten in C (row-major), Fortran (column-major) order, or preserve the C/Fortran o 2 min read Numpy MaskedArray.cumprod() function | Python numpy.MaskedArray.cumprod() Return the cumulative product of the masked array elements over the given axis.Masked values are set to 1 internally during the computation. However, their position is saved, and the result will be masked at the same locations. Syntax : numpy.ma.cumprod(axis=None, dtype=N 3 min read Like