NumPy cumprod preserves intermediate products while following a chosen accumulation axis
Multiplication across a sequence can be recorded as a single final product or as a series of running products. The second view shows how each new factor changes the accumulated result. Academia Master Trader explains NumPy cumprod in English for readers in Luxembourg, using small constructed arrays. These examples describe numerical operations, not reported investment outcomes. The focus is the distinction between a factor and the product reached after including that factor.
Follow each multiplication in order
After import numpy as np, define x = np.array([2,3,-1,4]). The call np.cumprod(x) returns [2,6,-6,-24]. The first running product is two. Multiplying by three gives six. Multiplying that result by minus one gives minus six, and multiplying by four gives minus twenty four. Every result includes all entries from the start through its own position.
Four input factors produce four output products. The function retains the intermediate values rather than returning only minus twenty four. It also differs from a cumulative sum: six in the second position comes from two multiplied by three, not from adding them. Naming the operation matters even when a particular example happens to contain a similar number.

Separate each factor from its running product
The figure places the original factors in gold and the accumulated products in grey. At the third position, the factor is minus one and the running product is minus six. The two rows describe different quantities. The fourth factor is four, while the fourth product is minus twenty four. A label should make that distinction explicit wherever the results are displayed.
For this signed integer sequence, the negative factor changes the sign of the running product. A zero factor would instead make that position's product zero, and subsequent multiplication by finite integer factors would keep it zero. For example, np.cumprod([2,0,3]) returns [2,0,0]. This follows ordinary multiplication; it is not a rule for replacing or ignoring zero entries.
Select separate row accumulations
Define a = np.array([[2,3,4],[5,2,1]]), with shape (2,3). The call np.cumprod(a,axis=1) returns [[2,6,24],[5,10,10]]. The running product restarts at the beginning of each row. The first row reaches twenty four. The second row begins at five and reaches ten. Multiplication by its final factor one leaves that running product unchanged.
The output keeps shape (2,3). Each position still belongs to its original row and column, but now contains a product through that point along the selected axis. Keeping the same shape does not mean keeping the original numerical meaning.
Compare columns with the flattened default
The call np.cumprod(a,axis=0) returns [[2,3,4],[10,6,4]]. Each column now accumulates downward, so its second product combines the entries from the first and second rows. This grouping differs from accumulation across each row.
Without an axis argument, np.cumprod(a) returns [2,6,24,120,240,240]. The matrix is flattened first, reading the first row followed by the second. Accumulation continues across the row boundary: the factor five multiplies the earlier product twenty four to produce one hundred twenty. The result is a one dimensional array of six products rather than a matrix of independent row products.
Choose a suitable numerical type
The optional dtype argument selects the returned type and the accumulator type. Integer multiplication can exceed the chosen type's capacity; NumPy uses modular arithmetic without raising an overflow error for these integer operations. Choose a type that suits the intended values and sequence length, rather than treating a familiar output shape as proof of suitable arithmetic.
Continue learning with Academia Master Trader at academiamastertrader.com.br and in Aprenda. Record the input factors, axis or flattened order, numerical type and output shape. Follow several products manually, including any sign change or zero. That makes the calculation explainable without turning a running product into a claim about future values.