# cumsum!

cumsum!(B, A, [dim])

Cumulative sum of `A` along a dimension, storing the result in `B`. The dimension defaults to 1.

## Examples

In the Julia programming language, the function cumsum!(B, A, [dim])

Computes the cumulative sum of array `A` along the specified dimension `dim` and stores the result in array `B`. If `dim` is not provided, the cumulative sum is computed along the first dimension by default.

``````julia> A = [1, 2, 3, 4];

julia> B = similar(A);

julia> cumsum!(B, A)
4-element Array{Int64,1}:
1
3
6
10``````

Common examples of its use:

1. Compute cumulative sum along the first dimension:

``````julia> A = [1, 2, 3, 4];
julia> B = similar(A);
julia> cumsum!(B, A)
4-element Array{Int64,1}:
1
3
6
10``````

This example computes the cumulative sum of the elements in array `A` along the first dimension and stores the result in `B`.

2. Compute cumulative sum along a specified dimension:
``````julia> A = [1 2 3; 4 5 6];
julia> B = similar(A);
julia> cumsum!(B, A, 2)
2×3 Array{Int64,2}:
1  3  6
4  9 15``````

Here, the cumulative sum of `A` is computed along the second dimension (columns) and stored in `B`.

Common mistake example:

``````julia> A = [1, 2, 3, 4];
julia> B = [0, 0, 0, 0, 0];
julia> cumsum!(B, A)
ERROR: DimensionMismatch("dimensions must match")``````

In this example, `B` is not the same size as the cumulative sum result. It's crucial to ensure that the size of `B` matches the expected size of the cumulative sum result to avoid this error.