The numpy.cumprod() function in NumPy computes the cumulative product of the elements in a given input array over a given axis.
numpy.cumprod(a, axis=None, dtype=None, out=None)
The numpy.cumprod() function takes the following parameter values:
a (required): This is the input array that contains numbers to be computed.axis (optional): This is the axis along which the product is determined.dtype (optional): This is the data type of the output array.out (optional): This is the alternate array where the result is placed.The numpy.cumprod() function returns an output array that holds the result.
import numpy as np# Creating an arrayx = np.array([1, 2, 3])# Invoking the numpy.cumprod() functionmyarray = np.cumprod(x, axis=0)print(x)print(myarray)
numpy module.x using the array() method.np.cumprod() function on the array. The result is assigned to the variable myarray.x.myarray.