cumprod!
cumprod!(B, A, [dim])
Cumulative product of A
along a dimension, storing the result in B
. The dimension defaults to 1.
Examples
-
Compute cumulative product along the default dimension:
julia> A = [2, 4, 6, 8]; julia> B = similar(A); julia> cumprod!(B, A) 4-element Array{Int64,1}: 2 8 48 384
This example computes the cumulative product of the elements in
A
along the default dimension (dimension 1) and stores the result inB
. -
Compute cumulative product along a specified dimension:
julia> A = [1 2 3; 4 5 6; 7 8 9]; julia> B = similar(A); julia> cumprod!(B, A, 2) 3×3 Array{Int64,2}: 1 2 6 4 20 120 7 56 504
In this example, the cumulative product is computed along dimension 2 of the matrix
A
and stored inB
. - Handle edge cases with empty arrays:
julia> A = Int64[]; julia> B = similar(A); julia> cumprod!(B, A) 0-element Array{Int64,1}
This example demonstrates that when the input array
A
is empty, the resulting cumulative product arrayB
is also empty.
Common mistake example:
julia> A = [1, 2, 3];
julia> B = similar(A);
julia> cumprod!(B, A, 2)
ERROR: DimensionMismatch("cumulative product dimension exceeds size of input array")
In this case, the specified dimension (2) for the cumulative product is larger than the size of the input array along that dimension. Make sure to provide a valid dimension within the range of the input array when using cumprod!
.
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.