Numpy MaskedArray.median() function | Python Last Updated : 18 Oct, 2019 Comments Improve Suggest changes Like Article Like Report numpy.MaskedArray.median() function is used to compute the median along the specified axis of a masked array.It returns the median of the array elements. Syntax : numpy.ma.median(arr, axis=None, out=None, overwrite_input=False, keepdims=False) Parameters: arr : [ ndarray ] Input masked array. axis :[ int, optional] Axis along which the median is computed. The default (None) is to compute the median over the flattened array. dtype : [dtype, optional] Type of the returned array, as well as of the accumulator in which the elements are multiplied. out : [ndarray, optional] A location into which the result is stored. -> If provided, it must have a shape that the inputs broadcast to. -> If not provided or None, a freshly-allocated array is returned. overwrite_input :[bool, optional] If True, then allow use of memory of input array for calculations. The input array will be modified by the call to median. This will save memory when you do not need to preserve the contents of the input array. Treat the input as undefined, but it will probably be fully or partially sorted. Default is False. Note that, if overwrite_input is True, and the input is not already an ndarray, an error will be raised. keepdims :[ bool, optional] If this is set to True, the axes which are reduced are left in the result as dimensions with size one. With this option, the result will broadcast correctly against the input array. Return : [median_along_axis, ndarray] A new array holding the result is returned unless out is specified, in which case a reference to out is returned. Code #1 : Python3 # Python program explaining # numpy.MaskedArray.median() 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([[1, 2], [ 3, -1], [ 5, -3]]) print ("Input array : ", in_arr) # Now we are creating a masked array. # by making entry as invalid. mask_arr = ma.masked_array(in_arr, mask =[[1, 0], [ 1, 0], [ 0, 0]]) print ("Masked array : ", mask_arr) # applying MaskedArray.median # methods to masked array out_arr = ma.median(mask_arr) print ("median of masked array along default axis : ", out_arr) Output: Input array : [[ 1 2] [ 3 -1] [ 5 -3]] Masked array : [[-- 2] [-- -1] [5 -3]] median of masked array along default axis : 0.5 Code #2 : Python3 # Python program explaining # numpy.MaskedArray.median() 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([[1, 0, 3], [ 4, 1, 6]]) print ("Input array : ", in_arr) # Now we are creating a masked array. # by making one entry as invalid. mask_arr = ma.masked_array(in_arr, mask =[[ 0, 0, 0], [ 0, 0, 1]]) print ("Masked array : ", mask_arr) # applying MaskedArray.median methods # to masked array out_arr1 = ma.median(mask_arr, axis = 0) print ("median of masked array along 0 axis : ", out_arr1) out_arr2 = ma.median(mask_arr, axis = 1) print ("median of masked array along 1 axis : ", out_arr2) Output: Input array : [[1 0 3] [4 1 6]] Masked array : [[1 0 3] [4 1 --]] median of masked array along 0 axis : [2.5 0.5 3.0] median of masked array along 1 axis : [1.0 2.5] Comment More infoAdvertise with us Next Article Numpy MaskedArray.median() function | Python jana_sayantan Follow Improve Article Tags : Python Python-numpy Python numpy-arrayManipulation Practice Tags : python Similar Reads Numpy MaskedArray.mean() function | Python numpy.MaskedArray.mean() function is used to return the average of the masked array elements along given axis.Here masked entries are ignored, and result elements which are not finite will be masked. Syntax : numpy.ma.mean(axis=None, dtype=None, out=None) Parameters: axis :[ int, optional] Axis alon 3 min read Numpy MaskedArray.sum() function | Python numpy.MaskedArray.median() function is used to compute the sum of the masked array elements over the given axis. Syntax : numpy.ma.sum(arr, axis=None, dtype=None, out=None, keepdims=False) Parameters: arr : [ ndarray ] Input masked array. axis :[ int, optional] Axis along which the sum is computed. 3 min read Numpy MaskedArray.std() function | Python numpy.MaskedArray.std() function is used to compute the standard deviation along the specified axis.Here masked entries are ignored. The standard deviation is computed for the flattened array by default, otherwise over the specified axis. Syntax : numpy.ma.std(arr, axis=None, dtype=None, out=None, d 3 min read Numpy MaskedArray.var() function | Python numpy.MaskedArray.var() function is used to compute the variance along the specified axis. It returns the variance of the masked array elements, a measure of the spread of a distribution. The variance is computed for the flattened array by default, otherwise over the specified axis. Syntax : numpy.m 3 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.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.ravel() function | Python numpy.MaskedArray.ravel() function is used to return a 1D version of self mask array, as a view. Syntax : numpy.ma.ravel(self, order='C') Parameters: order : [âCâ, âFâ, âAâ, âKâ, optional] By default, âCâ index order is used. --> The elements of a are read using this index order. --> âCâ means to in 2 min read numpy.ma.MaskedArray.nonzero() function - Python numpy.ma.MaskedArray.nonzero() function return the indices of unmasked elements that are not zero. This function returns a tuple of arrays, one for each dimension, containing the indices of the non-zero elements in that dimension. Syntax : numpy.ma.MaskedArray.nonzero(self) Return : [tuple] Indices 1 min read Python | Numpy nanmedian() function numpy.nanmedian() function can be used to calculate the median of array ignoring the NaN value. If array have NaN value and we can find out the median without effect of NaN value. Let's see different type of examples about numpy.nanmedian() method. Syntax: numpy.nanmedian(a, axis=None, out=None, ove 2 min read Like