Numpy MaskedArray.cumprod() function | Python Last Updated : 18 Oct, 2019 Comments Improve Suggest changes Like Article Like Report 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=None, out=None) Parameters: axis :[ int, optional] Axis along which the cumulative product is computed. The default (None) is to compute the cumprod over the flattened array. dtype : [dtype, optional] Type of the returned array, as well as of the accumulator in which the elements are multiplied. If dtype is not specified, it defaults to the dtype of arr, unless arr has an integer dtype with a precision less than that of the default platform integer. In that case, the default platform integer is used instead. 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 : [cumprod_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.cumprod() 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.cumprod # methods to masked array out_arr = mask_arr.cumprod() print ("cumulative product of masked array along default axis : ", out_arr) Output: Input array : [[ 1 2] [ 3 -1] [ 5 -3]] Masked array : [[-- 2] [-- -1] [5 -3]] cumulative sum of masked array along default axis : [-- 2 -- -2 -10 30] Code #2 : Python3 # Python program explaining # numpy.MaskedArray.cumprod() 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.cumprod methods # to masked array out_arr1 = mask_arr.cumprod(axis = 0) print ("cumulative product of masked array along 0 axis : ", out_arr1) out_arr2 = mask_arr.cumprod(axis = 1) print ("cumulative 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 --]] cumulative product of masked array along 0 axis : [[1 0 3] [4 0 --]] cumulative product of masked array along 1 axis : [[1 0 0] [4 4 --]] Comment More infoAdvertise with us Next Article Numpy MaskedArray.cumprod() function | Python jana_sayantan Follow Improve Article Tags : Python Python-numpy Python numpy-arrayManipulation Practice Tags : python Similar Reads Numpy MaskedArray.compressed() function - Python numpy.MaskedArray.compressed() function return all the non-masked data as a 1-D array. Syntax : numpy.MaskedArray.compressed(self) Return : [ndarray] A new ndarray holding the non-masked data is returned. Code #1 : Python3 # Python program explaining # numpy.MaskedArray.compressed() function # impor 1 min read Numpy MaskedArray.cumsum() function | Python numpy.MaskedArray.cumsum() Return the cumulative sum of the masked array elements over the given axis.Masked values are set to 0 internally during the computation. However, their position is saved, and the result will be masked at the same locations. Syntax : numpy.ma.cumsum(axis=None, dtype=None, o 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.argsort() 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.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.ma.MaskedArray.count() function - Python numpy.ma.MaskedArray.count() function count the non-masked elements of the array along the given axis. Syntax : numpy.ma.MaskedArray.count(self, axis=None, keepdims = no value) Parameters : axis : [None or int or tuple of ints, optional] Axis along which the count is performed. The default axis is N 2 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.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 Like