Numpy MaskedArray.mean() function | Python Last Updated : 18 Oct, 2019 Comments Improve Suggest changes Like Article Like Report 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 along which the mean is computed. The default (None) is to compute the mean 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. Return : [mean_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.mean() 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.mean # methods to masked array out_arr = mask_arr.mean() print ("mean of masked array along default axis : ", out_arr) Output: Input array : [[ 1 2] [ 3 -1] [ 5 -3]] Masked array : [[-- 2] [-- -1] [5 -3]] mean of masked array along default axis : 0.75 Code #2 : Python3 # Python program explaining # numpy.MaskedArray.mean() 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.mean methods # to masked array out_arr1 = mask_arr.mean(axis = 0) print ("mean of masked array along 0 axis : ", out_arr1) out_arr2 = mask_arr.mean(axis = 1) print ("mean of masked array along 1 axis : ", out_arr2) Output: Input array : [[1 0 3] [4 1 6]] Masked array : [[1 0 3] [4 1 --]] mean of masked array along 0 axis : [2.5 0.5 3.0] mean of masked array along 1 axis : [1.3333333333333333 2.5] Comment More infoAdvertise with us Next Article Numpy MaskedArray.mean() function | Python jana_sayantan Follow Improve Article Tags : Python Python-numpy Python numpy-arrayManipulation Practice Tags : python Similar Reads Numpy MaskedArray.median() function | Python 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 : 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.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.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.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.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 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 Like