..  cumprod(A, [dim])

Cumulative product along a dimension ``dim`` (defaults to 1).
See also :func:`cumprod!` to use a preallocated output array,
both for performance and to control the precision of the
output (e.g. to avoid overflow).


The cumprod function in Julia calculates the cumulative product along a specified dimension (dim). If dim is not provided, it defaults to 1. The function returns a new array containing the cumulative product values.

julia> cumprod([2, 3, 4])
3-element Array{Int64,1}:

This example calculates the cumulative product of the elements in the array [2, 3, 4].

julia> A = [1 2 3; 4 5 6; 7 8 9];
julia> cumprod(A, 2)
3×3 Array{Int64,2}:
  1   2   6
  4  20 120
  7  56 504

Here, the cumprod function is applied along dim=2 (rows) of the matrix A, resulting in a new matrix with cumulative product values along each row.

julia> B = [0.1, 0.01, 0.001];
julia> cumprod(B)
3-element Array{Float64,1}:

In this example, the cumprod function is used on an array of floating-point numbers.

Note that the cumprod function can also be used with higher-dimensional arrays by specifying the appropriate dim value.

It's important to mention the cumprod! function, which allows for using a preallocated output array to improve performance and control the precision of the output, especially to prevent overflow.

See Also

abs2, beta, binomial, ceil, cell, cross, ctranspose, ctranspose!, cummin, cumprod, cumprod!, cumsum, cumsum!, cumsum_kbn, div, divrem, eigfact, eigfact!, eigmin, eps, erf, erfc, erfcinv, erfcx, erfi, erfinv, exp, exp10, exp2, expm1, exponent, factor, factorial, factorize, floor, gcd, invmod, log, log10, log1p, log2, logspace, max, min, mod, mod1, modf, next, nextpow, nextprod, num, primes, primesmask, prod, realmin, sqrt, sum!, sumabs, sumabs!, sumabs2, sumabs2!,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field

Checking you are not a robot: