Numpy MaskedArray.prod() function | Python Last Updated : 18 Oct, 2019 Comments Improve Suggest changes Like Article Like Report numpy.MaskedArray.prod() function is used to compute the product of the array elements over the given axis.Here masked elements are set to 1 internally for computation. Syntax : numpy.ma.prod(self, axis=None, dtype=None, out=None, keepdims=False) Parameters: arr : [ ndarray ] Input masked array. axis :[ int, optional] Axis along which the product is computed. The default (None) is to compute the product 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. 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 : [product_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.prod() 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.prod # methods to masked array out_arr = ma.prod(mask_arr) print ("product of masked array along default axis : ", out_arr) Output: Input array : [[ 1 2] [ 3 -1] [ 5 -3]] Masked array : [[-- 2] [-- -1] [5 -3]] product of masked array along default axis : 30 Code #2 : Python3 # Python program explaining # numpy.MaskedArray.prod() 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.prod methods # to masked array out_arr1 = ma.prod(mask_arr, axis = 0) print ("product of masked array along 0 axis : ", out_arr1) out_arr2 = ma.prod(mask_arr, axis = 1) print ("product of masked array along 1 axis : ", out_arr2) Output: Input array : [[1 0 3] [4 1 6]] Masked array : [[1 0 3] [4 1 --]] product of masked array along 0 axis : [4 0 3] product of masked array along 1 axis : [0 4] Comment More infoAdvertise with us Next Article Numpy MaskedArray.prod() function | Python jana_sayantan Follow Improve Article Tags : Python Python-numpy Python numpy-arrayManipulation Practice Tags : python Similar Reads Numpy MaskedArray.power() function | Python numpy.MaskedArray.power() function is used to compute element-wise base array raised to power from second array. It raise each base in arr1 to the positionally-corresponding power in arr2. arr1 and arr2 must be broadcastable to the same shape. Note that an integer type raised to a negative integer p 2 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.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.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.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.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.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 Like