numpy.nancumsum() in Python Last Updated : 29 Nov, 2018 Comments Improve Suggest changes Like Article Like Report numpy.nancumsum() function is used when we want to compute the cumulative sum of array elements over a given axis treating Not a Numbers (NaNs) as zero. The cumulative sum does not change when NaNs are encountered and leading NaNs are replaced by zeros. Zeros are returned for slices that are all-NaN or empty. Syntax : numpy.nancumsum(arr, axis=None, dtype=None, out=None) Parameters : arr : [array_like] Array containing numbers whose cumulative sum is desired. If arr is not an array, a conversion is attempted. axis : Axis along which the cumulative sum is computed. The default is to compute the sum of the flattened array. dtype : 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 : A new array holding the result is returned unless out is specified, in which case it is returned. Code #1 : Working Python # Python program explaining # numpy.nancumsum() function import numpy as geek in_num = 10 print ("Input number : ", in_num) out_sum = geek.nancumsum(in_num) print ("cumulative sum of input number : ", out_sum) Output : Input number : 10 cumulative sum of input number : [10] Code #2 : Python # Python program explaining # numpy.nancumsum() function import numpy as geek in_arr = geek.array([[2, 4, 6], [1, 3, geek.nan]]) print ("Input array : ", in_arr) out_sum = geek.nancumsum(in_arr) print ("cumulative sum of array elements: ", out_sum) Output : Input array : [[ 2. 4. 6.] [ 1. 3. nan]] cumulative sum of array elements: [ 2. 6. 12. 13. 16. 16.] Code #3 : Python # Python program explaining # numpy.nancumsum() function import numpy as geek in_arr = geek.array([[2, 4, 6], [1, 3, geek.nan]]) print ("Input array : ", in_arr) out_sum = geek.nancumsum(in_arr, axis = 0) print ("cumulative sum of array elements taking axis 0: ", out_sum) Output : Input array : [[ 2. 4. 6.] [ 1. 3. nan]] cumulative sum of array elements taking axis 0: [[ 2. 4. 6.] [ 3. 7. 6.]] Comment More infoAdvertise with us Next Article numpy.nancumsum() in Python J jana_sayantan Follow Improve Article Tags : Python Python-numpy Python numpy-Mathematical Function Practice Tags : python Similar Reads numpy.nansum() in Python numpy.nansum() function computes the sum of array elements over a given axis, treating NaN (Not a Number) values as zero. This is useful when you want to ignore missing or undefined values in your computation. For Example:Pythonimport numpy as np a = np.array([1.0, 2.0, np.nan, 4.0]) res = np.nansum 2 min read numpy.nancumprod() in Python numpy.nancumprod() function is used when we want to compute the cumulative product of array elements over a given axis treating Not a Numbers (NaNs) as one. The cumulative product does not change when NaNs are encountered and leading NaNs are replaced by ones. Ones are returned for slices that are a 3 min read numpy.nanmin() in Python numpy.nanmin()function is used when to returns minimum value of an array or along any specific mentioned axis of the array, ignoring any Nan value. Syntax : numpy.nanmin(arr, axis=None, out=None) Parameters : arr :Input array. axis :Axis along which we want the min value. Otherwise, it will consider 2 min read numpy.isnan() in Python The numpy.isnan() function tests element-wise whether it is NaN or not and returns the result as a boolean array. Syntax :Â numpy.isnan(array [, out]) Parameters :Â array : [array_like]Input array or object whose elements, we need to test for infinity out : [ndarray, optional]Output array placed wit 2 min read numpy.nan_to_num() in Python numpy.nan_to_num() function is used when we want to replace nan(Not A Number) with zero and inf with finite numbers in an array. It returns (positive) infinity with a very large number and negative infinity with a very small (or negative) number. Syntax : numpy.nan_to_num(arr, copy=True) Parameters 2 min read Like