# numpy.nancumprod () in Python

| |

`numpy.nancumprod()` is used when we want to calculate the cumulative product of array elements along a given axis, considering non-numbers (NaN) as a whole. The total product does not change when NaNs are encountered and the leading NaNs are replaced by them. Units are returned for slices that are completely NaN or empty.

Syntax: numpy.nancumprod (arr, axis = None, dtype = None, out = None)

Parameters:
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: Work

 ` # Python program explaining ` ` # numpy.nancumprod () function `   ` import ` ` numpy as geek ` ` in_num ` ` = ` ` 10 `   ` print ` ` (` ` "Input number:" ` `, in_num) ` ` `  ` out_prod ` ` = ` ` geek.nancumprod (in_num) ` ` print ` ` (` ` "cumulative product of input number:" ` `, out_prod) `

Output:

` Input number: 10 cumulative product of input number:  `

Code # 2:

 ` # Python program explaining ` ` # numpy.nancumprod () function ` ` `  ` import ` ` numpy as geek `   ` in_arr ` ` = ` ` geek.array ([[` ` 2 ` , ` 2 ` `, ` ` 2 ` `], [` ` 2 ` `, ` ` 2 ` `, geek.nan]]) `   ` print ` ` (` ` "Input array:" ` `, in_arr) ` ` `  ` out_prod ` ` = ` ` geek.nancumprod (in_arr) ` ` print ` ` (` ` "cumulative product of array elements:" ` `, out_prod) `

Output:

` Input array : [[2. 2. 2.] [2. 2. nan]] cumulative product of array elements: [2. 4. 8. 16. 32. 3 2.] `

Code # 3:

 ` # Python program explaining ` ` # numpy.nancumprod () function `   ` import ` ` numpy as geek `   ` in_arr ` ` = ` ` geek.array ([[` ` 2 ` `, ` ` 2 ` `, ` ` 2 ` `], [` ` 2 ` `, ` ` 2 ` `, geek.nan]]) ` ` `  ` print ` ` (` `" Input array: "` `, in_arr) ` ` `  ` out_prod ` ` = ` ` geek.nancumprod (in_arr, axis ` ` = ` ` 1 ` `) ` ` print ` ` (` `" cumulative product of array elements taking axis 1: "` `, out_prod) `

Output:

` Input array: [[2. 2. 2.] [2. 2. nan]] cumulative product of array elements taking axis 1: [[2. 4. 8.] [2. 4. 4.]] `

## Shop Learn programming in R: courses

\$ Best Python online courses for 2022

\$ Best laptop for Fortnite

\$ Best laptop for Excel

\$ Best laptop for Solidworks

\$ Best laptop for Roblox

\$ Best computer for crypto mining

\$ Best laptop for Sims 4

\$

Latest questions

NUMPYNUMPY

psycopg2: insert multiple rows with one query

NUMPYNUMPY

How to convert Nonetype to int or string?

NUMPYNUMPY

How to specify multiple return types using type-hints

NUMPYNUMPY

Javascript Error: IPython is not defined in JupyterLab

## Wiki

Python OpenCV | cv2.putText () method

numpy.arctan2 () in Python

Python | os.path.realpath () method

Python OpenCV | cv2.circle () method

Python OpenCV cv2.cvtColor () method

Python - Move item to the end of the list

time.perf_counter () function in Python

Check if one list is a subset of another in Python

Python os.path.join () method