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 all-NaN or empty.
Syntax : numpy.nancumprod(arr, axis=None, dtype=None, out=None)
arr : [array_like] Array containing numbers whose sum is desired. If arr is not an array, a conversion is attempted.
axis : Axis along which the cumulative product is computed. The default is to compute the product 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
Input number : 10 cumulative product of input number : 
Code #2 :
Input array : [[ 2. 2. 2.] [ 2. 2. nan]] cumulative product of array elements: [ 2. 4. 8. 16. 32. 32.]
Code #3 :
Input array : [[ 2. 2. 2.] [ 2. 2. nan]] cumulative product of array elements taking axis 1: [[ 2. 4. 8.] [ 2. 4. 4.]]
- Python - Read blob object in python using wand library
- Python | Index of Non-Zero elements in Python list
- Python | Convert list to Python array
- Python | PRAW - Python Reddit API Wrapper
- Important differences between Python 2.x and Python 3.x with examples
- Reading Python File-Like Objects from C | Python
- Python | Merge Python key values to list
- twitter-text-python (ttp) module - Python
- MySQL-Connector-Python module in Python
- Python | Sort Python Dictionaries by Key or Value
- Python | Set 4 (Dictionary, Keywords in Python)
- Python | Add Logging to a Python Script
- Python | Add Logging to Python Libraries
- Python | Visualizing O(n) using Python
- bin() in Python
- gcd() in Python
- Python if else
- max() and min() in Python
- SQL using Python | Set 1
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.